I'm trying to write my first cookie on python but when i import cookie or even http.cookie it gives me the below error

import cookie

    c = cookie.SimpleCookie()

    c["value"] = "first"

    print (c)

ImportError: No module named 'cookie'
[Finished in 0.3s with exit code 1]
[shell_cmd: python -u "C:\Users\hohait\Desktop\test.py"]
[dir: C:\Users\hohait\Desktop]
[path: C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\NetSarang;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Lotus\Notes;C:\Program Files\IBM\Client Access\Emulator;C:\Program Files\IBM\Client Access\Shared;C:\Program Files\IBM\Client Access";C:\Users\hohait\AppData\Local\Programs\Python\Python35-32";C:\Users\hohait\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\hohait\AppData\Local\Programs\Python\Python35-32\;C:\Users\hohait\AppData\Local\Programs\Python\Python35-32]

1 Year
Discussion Span
Last Post by <HHH>

It's in http.cookie for Python 3.x.
So import is from http import cookies

For all about HTTP use Requests

>>> import requests
>>> url = 'http://httpbin.org/cookies'
>>> cookies = dict(cookies='are good to eat')
>>> r = requests.get(url, cookies=cookies)
>>> print(r.text)
  "cookies": {
    "cookies": "are good to eat"

Edited by snippsat



I also have tried import use
from http import cookies
and it genrates the same error
ImportError: cannot import name 'cookie


It's part of standar library,so it should work.
Here a run in Python 3.4.

>>> from http import cookies
>>> a_cooike = cookies.SimpleCookie()
>>> a_cooike['Base'] = 'cream'
>>> print(a_cooike)
Set-Cookie: Base=cream

The default placement for python 3.5 is terrible,what are developers thinking about?
I know the answer and it security relatet,but i don't like it.

Follow this,the you get better placement C:\Python35-32
Make sure under installation that you mark for Path and pip.
Test pip and upgrade pip.
Here a run and use virtualenv,so you see how pip work from clean setup.

λ activate

(test) C:\test\Scripts
λ python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\test\lib\site-packages

(test) C:\test\Scripts
λ pip -V
pip 8.1.2 from c:\test\lib\site-packages (python 3.4)

(test) C:\test\Scripts
λ pip install requests
Collecting requests
  Downloading requests-2.11.0-py2.py3-none-any.whl (514kB)
    100% |################################| 522kB 1.0MB/s
Installing collected packages: requests
Successfully installed requests-2.11.0

(test) C:\test\Scripts
λ python
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__

#And also test cookies
>>> from http import cookies

Edited by snippsat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.