views:

83

answers:

2

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?

+1  A: 

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.

hcalves
Generally, as a rule, I don't bother trying to reuse HttpRequest objects unless I have a specific, performance-driven need to do so. Just single-shot 'em
Bryan Ross
A: 

I was running into this same exception today, using this code:

    conn = httplib.HTTPConnection(self._host, self._port)
    conn.putrequest('GET',
        '/retrieve?id={0}'.format(parsed_store_response['id']))
    retr_response = conn.getresponse()

I didn't notice that I was using putrequest rather than request; I was mixing my interfaces. ResponseNotReady is raised because I haven't actually sent the request yet.

phasetwenty