Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name exceptions since 1.3 #65

Closed
MOON-CLJ opened this issue Mar 27, 2012 · 12 comments
Closed

ImportError: cannot import name exceptions since 1.3 #65

MOON-CLJ opened this issue Mar 27, 2012 · 12 comments

Comments

@MOON-CLJ
Copy link

from urllib3 import HTTPSConnectionPool
File "/usr/local/lib/python2.7/dist-packages/urllib3-1.3-py2.7.egg/urllib3/init.py", line 22, in
from . import exceptions
ImportError: cannot import name exceptions

with easy_install

@shazow
Copy link
Member

shazow commented Mar 27, 2012

Which version of Python are you using?
On Mar 27, 2012 5:50 AM, "MOON-CLJ" <
reply@reply.github.com>
wrote:

from urllib3 import HTTPSConnectionPool
File
"/usr/local/lib/python2.7/dist-packages/urllib3-1.3-py2.7.egg/urllib3/init.py",
line 22, in
from . import exceptions
ImportError: cannot import name exceptions

with easy_install


Reply to this email directly or view it on GitHub:
#65

@MOON-CLJ
Copy link
Author

2.7

@shazow
Copy link
Member

shazow commented Mar 27, 2012

Ah should have seen it in the path. I'm having trouble reproducing it though...

$ easy_install -U urllib3
Searching for urllib3
Reading http://pypi.python.org/simple/urllib3/
Reading https://github.com/shazow/urllib3
Reading http://code.google.com/p/urllib3/
Reading http://urllib3.readthedocs.org/
Best match: urllib3 1.3
Downloading http://pypi.python.org/packages/source/u/urllib3/urllib3-1.3.tar.gz#md5=6ae9acdaee2628b1c8b1de25b7e6c9da
Processing urllib3-1.3.tar.gz
Running urllib3-1.3/setup.py -q bdist_egg --dist-dir /var/folders/++/++7MiU++6+0++4RjPqRgNE+0K9c/-Tmp-/easy_install-RyJmpc/urllib3-1.3/egg-dist-tmp-MKXgRp
zip_safe flag not set; analyzing archive contents...
dummyserver.server: module references __file__
Adding urllib3 1.3 to easy-install.pth file

Installed /Users/shazow/env/urllib3/lib/python2.7/site-packages/urllib3-1.3-py2.7.egg
Processing dependencies for urllib3
Finished processing dependencies for urllib3

Any ideas?

@shazow
Copy link
Member

shazow commented Mar 27, 2012

Ah, just noticed you meant the error happens on import, not install. Checking.

@shazow
Copy link
Member

shazow commented Mar 27, 2012

Hmm, seems to work during import too:

$ python
Python 2.7.2 (default, Dec 16 2011, 19:20:09) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib3 import HTTPSConnectionPool
>>> import urllib3
>>> urllib3.exceptions
<module 'urllib3.exceptions' from '/Users/shazow/env/urllib3/lib/python2.7/site-packages/urllib3-1.3-py2.7.egg/urllib3/exceptions.pyc'>
>>>

@MOON-CLJ
Copy link
Author

oh i know, i check this
it's just because i used eventlet.import_patched
urllib3 = eventlet.import_patched('urllib3')
from urllib3 import HTTPSConnectionPool

but with version 1.2.2 this will be fine

@shazow
Copy link
Member

shazow commented Mar 27, 2012

Ah, that is indeed a problem. Any interest in fixing it? :)

I was hoping to have exceptions available under urllib3.exceptions without an extra import if possible.

@MOON-CLJ
Copy link
Author

ok i'll try to do this

@MOON-CLJ
Copy link
Author

clj@clj-laptop:~/dev$ sudo easy_install urllib3==1.2.2
Searching for urllib3==1.2.2
Best match: urllib3 1.2.2
Processing urllib3-1.2.2-py2.7.egg
urllib3 1.2.2 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/urllib3-1.2.2-py2.7.egg
Processing dependencies for urllib3==1.2.2
Finished processing dependencies for urllib3==1.2.2
clj@clj-laptop:~/dev$ python
Python 2.7.2+ (default, Oct 4 2011, 20:03:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import eventlet
urllib3 = eventlet.import_patched('urllib3')
from urllib3 import exceptions
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name exceptions

after viewing the source code of eventlet
i think this is just a eventlet.import_patched bug(as shown above)
but i still dont know exactly where is the bug in eventlet
i'll check it again later

if you have times, you can check this
https://bitbucket.org/which_linden/eventlet/src/a60be8a9cdb5/eventlet/patcher.py

if you find what causes this,
please let me know
thanks in advance

@MOON-CLJ
Copy link
Author

urllib3 version 1.2.2

Python 2.7.2+ (default, Oct  4 2011, 20:03:08) 
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import eventlet
>>> urllib3 = eventlet.import_patched('urllib3')
>>> dir(urllib3)
['HTTPConnectionPool', 'HTTPError', 'HTTPResponse', 'HTTPSConnectionPool', 'MaxRetryError', 'PoolManager', 'ProxyManager', 'SSLError', 'TimeoutError', '__author__', '__builtins__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__path__', '__version__', '_collections', 'connection_from_url', 'connectionpool', 'encode_multipart_formdata', 'exceptions', 'filepost', 'get_host', 'make_headers', 'packages', 'poolmanager', 'proxy_from_url', 'request', 'response']
>>> import urllib3
>>> dir(urllib3)
['HTTPConnectionPool', 'HTTPError', 'HTTPResponse', 'HTTPSConnectionPool', 'MaxRetryError', 'PoolManager', 'ProxyManager', 'SSLError', 'TimeoutError', '__author__', '__builtins__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__path__', '__version__', 'connection_from_url', 'encode_multipart_formdata', 'get_host', 'make_headers', 'proxy_from_url']

after import urllib3
some attributes were lost

@shazow
Copy link
Member

shazow commented Mar 30, 2012

Hmm, here's the set difference:

['_collections',
 'request',
 'connectionpool',
 'filepost',
 'poolmanager',
 'exceptions',
 'packages',
 'response']

@MOON-CLJ
Copy link
Author

it's not necessary to use eventlet.import_patched('urllib3')(but the bug is existed exactly)
eventlet.patcher.monkey_patch() can patch all the modules that eventlet can provide
so
eventlet.patcher.monkey_patch()
import urllib3
it will work for me

@shazow shazow closed this as completed Jun 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants