Hello,

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]

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"
  }
}

Hello,

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?
C:\Users\hohait\AppData\Local\Programs\Python\Python35-32
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.

C:\test\Scripts
λ 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__
'2.11.0'

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

Thanks it working now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.