2015-10-16 108 views
0

我是python的新手,我在尝试从six.moves.http_client执行基本导入时遇到问题。无法从six.moves.http_client导入HTTPConnection

我已经更新可在PIP六到最新版本:

$ pip show six 
--- 
Metadata-Version: 2.0 
Name: six 
Version: 1.10.0 
Summary: Python 2 and 3 compatibility utilities 
Home-page: http://pypi.python.org/pypi/six/ 
Author: Benjamin Peterson 
Author-email: [email protected] 
License: MIT 
Location: /Library/Python/2.7/site-packages 
Requires: 

但试图从http_client导入例如在HttpConnection的时候,它给了我一个错误:

$ python 
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from six.moves.http_client import HTTPConnection 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named http_client 

但我可以从six.moves进口http_client

>>> from six.moves import http_client 
>>> http_client.responses 
{200: 'OK', 201: 'Created', 202: 'Accepted', 203: 'Non-Authoritative Information', 204: 'No Content', 205: 'Reset Content', 206: 'Partial Content', 400: 'Bad Request', 401: 'Unauthorized', 402: 'Payment Required', 403: 'Forbidden', 404: 'Not Found', 405: 'Method Not Allowed', 406: 'Not Acceptable', 407: 'Proxy Authentication Required', 408: 'Request Timeout', 409: 'Conflict', 410: 'Gone', 411: 'Length Required', 412: 'Precondition Failed', 413: 'Request Entity Too Large', 414: 'Request-URI Too Long', 415: 'Unsupported Media Type', 416: 'Requested Range Not Satisfiable', 417: 'Expectation Failed', 100: 'Continue', 101: 'Switching Protocols', 300: 'Multiple Choices', 301: 'Moved Permanently', 302: 'Found', 303: 'See Other', 304: 'Not Modified', 305: 'Use Proxy', 306: '(Unused)', 307: 'Temporary Redirect', 500: 'Internal Server Error', 501: 'Not Implemented', 502: 'Bad Gateway', 503: 'Service Unavailable', 504: 'Gateway Timeout', 505: 'HTTP Version Not Supported'} 
>>> http_client.HTTPConnection 
<class httplib.HTTPConnection at 0x106de96d0> 

有谁能告诉我我是什么在这里完全失踪?

回答

0

六使用复杂的进口技巧来做它的魔法。您可以在其源代码中查看类_SixMetaPathImporter。没有真正的软件包six.moves.http_client。