python httplib2 - AttributeError: 'NoneType' object has no attribute 'makefile'

python version:2.6

httplib2 version:0.6    $Rev$(author:Joe Gregorio)

错误信息:

Traceback (most recent call last):  

  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' 

失去连接后没有重新连接,修改/usr/lib/python2.6/dist-packages/httplib2/__init__.py,相关代码如下,添加粗体部分:

1     def _conn_request(self, conn, request_uri, method, body, headers):

2         for i in range(2):

3             try:

4                 if conn.sock is None: 5  conn.connect() 6                 conn.request(method, request_uri, body, headers)

7             except socket.timeout: 8                 raise

 

python version:2.7

httplib2 version:0.7.2

该版本中此bug已经被修改。

 

参考:

http://stackoverflow.com/questions/3226218/httplib2-attributeerror-nonetype-object-has-no-attribute-makefile

 

原文:http://www.cnblogs.com/congbo/archive/2012/08/16/2641917.html

你可能感兴趣的:(attribute)