Httplib2 AttributeError:“NoneType”对象没有属性“makefile”

2024-04-26 14:07:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我该怎么解决?
注:在谷歌上,我发现这是一个httplib2错误,但我不知道如何使用人们提供的补丁。

Traceback (most recent call last):  
  File "alt_func.py", line 18, in <module>  
    func(code)
  File "alt_func.py", line 9, in func
    resp, content = h.request(url_string, "GET", headers={'Referer': referer})  
  File "/usr/lib/pymodules/python2.6/httplib2/__init__.py", line 1099, in request  
    (response, new_content) = self._request(conn, authority, uri, request_uri, method,     body, headers, redirections, cachekey)  
  File "/usr/lib/pymodules/python2.6/httplib2/__init__.py", line 901, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)  
  File "/usr/lib/pymodules/python2.6/httplib2/__init__.py", line 871, in _conn_request  
    response = conn.getresponse()  
  File "/usr/lib/python2.6/httplib.py", line 984, in getresponse  
    method=self._method)  
  File "/usr/lib/python2.6/httplib.py", line 330, in __init__  
    self.fp = sock.makefile('rb', 0)  
AttributeError: 'NoneType' object has no attribute 'makefile'  

Tags: inpyselfinitrequestlibusrline
3条回答

这是一个已知问题:http://code.google.com/p/httplib2/issues/detail?id=96

似乎记录了一些欺骗,或者可能是由不同情况引起的相同症状:

您已经创建了一个HTTPConnection实例,但是它没有连接到任何东西,因此sock仍然具有None的初始值

你能发布一些显示这个失败的代码吗?您正在使用/尝试使用哪些修补程序

如果要连接的服务器未运行或位于其他端口上,也会出现此错误。如果你问我的话,这是一个误导性的错误信息。

相关问题 更多 >