python 六的奇怪问题:无法导入 urllib

Weird issue with python six: cannot import urllib

raven ships with its own version of the six 模块似乎阻止我导入存在于独立六模块中的模块。请看下面:

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

要重现这一点,请在您的虚拟环境中安装 requests==0.14.1 以及 motoraven 以及 运行 以下脚本:

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

如有任何提示,我们将不胜感激。

因为这个问题似乎很难重现,所以它可能更适合我们的支持电子邮件 - support@getsentry.com - 而不是 Whosebug。请在那里询问,我们会尽力提供帮助。

我收到 Sentry 支持人员的回复并使用他们的提示,我发现如果您安装 requests-0.14.2(我已经安装),这个错误很容易出现。我升级了请求,但它不再发生了。

相关link:Moto issue on GitHub