我正在使用 python 为 elgg 编写一个 REST 客户端,即使请求成功,我也会得到以下响应:
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
查看标题,我看到 ('content-length', '5749'),所以我知道那里有一个页面,但我无法使用 .read() 来查看它,因为出现了异常。 ResponseNotReady 是什么意思,为什么我看不到返回的内容?
最佳答案
以前的答案是正确的,但在另一种情况下您可能会遇到该异常:
在不完全读取任何中间响应的情况下发出多个请求。
例如:
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
等等。
关于Python httplib ResponseNotReady,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3231543/