Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python httplib ResponseNotReady

I'm writing a REST client for elgg using python, and even when the request succeeds, I get this in response:

Traceback (most recent call last):   File "testclient.py", line 94, in <module>     result = sendMessage(token, h1)   File "testclient.py", line 46, in sendMessage     res = h1.getresponse().read()   File "C:\Python25\lib\httplib.py", line 918, in getresponse     raise ResponseNotReady() httplib.ResponseNotReady 

Looking at the header, I see ('content-length', '5749'), so I know there is a page there, but I can't use .read() to see it because the exception comes up. What does ResponseNotReady mean and why can't I see the content that was returned?

like image 613
directedition Avatar asked Jul 12 '10 19:07

directedition


2 Answers

Previous answers are correct, but there's another case where you could get that exception:

Making multiple requests without reading any intermediate responses completely.

For instance:

conn.request('PUT',...) conn.request('GET',...) # will not work: raises ResponseNotReady  conn.request('PUT',...) r = conn.getresponse() r.read() # <-- that's the important call! conn.request('GET',...) r = conn.getresponse() r.read() # <-- same thing 

and so on.

like image 168
Bokeh Avatar answered Oct 09 '22 06:10

Bokeh


Make sure you don't reuse the same object from a previous connection. You will hit this once the server keep-alive ends and the socket closes.

like image 29
hcalves Avatar answered Oct 09 '22 06:10

hcalves