Ad

Weird Issue With Python Six: Cannot Import Urllib

- 1 answer

raven ships with its own version of the six module which seems to prevent me from importing a module which exists in the standalone six module. Please see below:

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> 
>>> 
>>> from raven.utils import six       
>>> dir(six.moves)
['__doc__', '__name__']
>>> 
>>> 
>>> import six
>>> six.__version__
'1.9.0'
>>> 
>>> 
>>> 
>>> dir(six.moves)
['BaseHTTPServer', 'CGIHTTPServer', 'SimpleHTTPServer', 'StringIO', 'UserDict', 'UserList', 'UserString', '__doc__', '__name__', '_dummy_thread', '_thread', 'builtins', 'cPickle', 'cStringIO', 'configparser', 'copyreg', 'dbm_gnu', 'email_mime_base', 'email_mime_multipart', 'email_mime_nonmultipart', 'email_mime_text', 'filter', 'filterfalse', 'html_entities', 'html_parser', 'http_client', 'http_cookiejar', 'http_cookies', 'input', 'intern', 'map', 'queue', 'range', 'reduce', 'reload_module', 'reprlib', 'shlex_quote', 'socketserver', 'tkinter', 'tkinter_colorchooser', 'tkinter_commondialog', 'tkinter_constants', 'tkinter_dialog', 'tkinter_dnd', 'tkinter_filedialog', 'tkinter_font', 'tkinter_messagebox', 'tkinter_scrolledtext', 'tkinter_simpledialog', 'tkinter_tix', 'tkinter_tkfiledialog', 'tkinter_tksimpledialog', 'tkinter_ttk', 'urllib', 'urllib_error', 'urllib_parse', 'urllib_robotparser', 'winreg', 'xmlrpc_client', 'xmlrpc_server', 'xrange', 'zip', 'zip_longest']
>>> 
>>> 
>>> 
>>> 
>>> import six.moves.urllib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named urllib
>>> 
>>> 
>>> 

To reproduce this, install requests==0.14.1 in your virtual environment along with moto and raven and run the following script:

from raven.utils import six as six1
from moto import mock_s3

Any hints would be appreciated.

Ad

Answer

I heard back from Sentry Support and using their hint, I discovered that if you install requests-0.14.2 (which I had installed), this error easily surfaces. I upgrade requests and it doesn't happen any more.

Related link: Moto issue on GitHub

Ad
source: stackoverflow.com
Ad