views:

160

answers:

4

How do I fix this?
PS: On googling, I found that this is some httplib2 bug but I didn't understand how to use the patches people have provided.

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'  
A: 

You have created an HTTPConnection instance, but is it not connected to anything, so the sock still has the initial value of None

Can you post some code that exhibits this failure? Which patches are you using/trying to use

gnibbler
A: 

I am experiencing an identical problem with the 'NoneType' object has no attribute 'makefile' AttributeError. I am trying to use a proxy and here is the code I am trying to get working:

>>> import httplib2
>>> import socks
>>> httplib2.debuglevel = 4
>>> h = httplib2.Http(proxy_info = 
... httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, '68.194.72.179', 8008))
>>> r, c = h.request("http://www.portablepython.com/")
connect: (www.portablepython.com, 80)
connect fail: ('www.portablepython.com', 80)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/httplib2/__init__.py", line 1129, in request
  File "build/bdist.linux-x86_64/egg/httplib2/__init__.py", line 901, in _request
  File "build/bdist.linux-x86_64/egg/httplib2/__init__.py", line 871, in _conn_request
  File "/usr/lib64/python2.5/httplib.py", line 919, in getresponse
    method=self._method)
  File "/usr/lib64/python2.5/httplib.py", line 324, in __init__
    self.fp = sock.makefile('rb', 0)
AttributeError: 'NoneType' object has no attribute 'makefile'
Shaheeb Roshan
A: 

This is a known issue: http://code.google.com/p/httplib2/issues/detail?id=96

There appear to be some dupes logged, or perhaps the same symptom arising from different circumstances:

StevenC
Sorry, I missed your update where you stated you found a relevant bug. It's possible one of the others helps you better than the one you found.
StevenC
A: 

You will also get this error if the server you are tying to connect to is not running or is on a different port. Quite a misleading error message, if you ask me.

CM Lubinski