Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.2 won't import cookielib

Tags:

python

I have looked everywhere for this and just cannot find the answer. I have checked my python version and it is version 3.2 . When I try to import cookielib I receive:

ImportError: No module named cookielib

I have seen that in Python 3.0 it was renamed to http.cookiejar and that it would auto import cookielib.

I thought that maybe there was some wild error in my python configuration so I thought I should try and import http.cookiejar like this import http.cookiejar. That did not work all and I get and error:

EOFError: EOF read where not expected.

This is not the error I had expected becuase import http.cookies imports just fine.

Does anybody have a solution to this problem? What am I overlooking?

Full Error:

Traceback (most recent call last):
  File "C:\Users\Spencer\Downloads\selenium-2.20.0.tar\selenium-2.20.0\selenium-2.20.0\test", line 1, in <module>
    import urllib.request, urllib.parse, http.cookiejar
EOFError: EOF read where not expected
like image 388
Sneitzke38 Avatar asked Mar 25 '12 03:03

Sneitzke38


3 Answers

The automatic renaming business only applies if you use 2to3. Therefore, you have to import http.cookiejar.

The error EOFError: EOF read where not expected is only ever thrown by Python marshalling. Most likely, this is caused by a race condition fixed in Python 3.3, where multiple processes tried to write concurrently to the pyc file. Deleting all .pyc files may be a workaround.

like image 77
phihag Avatar answered Nov 17 '22 21:11

phihag


try:
    import cookielib
except:
    import http.cookiejar
    cookielib = http.cookiejar
like image 21
Joel Silva Avatar answered Nov 17 '22 20:11

Joel Silva


The cookielib module has been renamed to http.cookiejar in Python 3.0. The 2to3 tool will automatically adapt imports when converting your sources to 3.0.

like image 22
Roozbeh Avatar answered Nov 17 '22 21:11

Roozbeh