dir*_*ion 34 python rest http httplib
我正在使用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
Run Code Online (Sandbox Code Playgroud)
看看标题,我看到('content-length','5749'),所以我知道那里有一个页面,但我不能使用.read()来查看它,因为异常出现了.ResponseNotReady是什么意思,为什么我看不到返回的内容?
Bok*_*keh 59
以前的答案是正确的,但还有另一种情况,你可以得到这个例外:
发出多个请求而不完全阅读任何中间响应.
例如:
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
Run Code Online (Sandbox Code Playgroud)
等等.
hca*_*ves 38
确保不要重复使用先前连接中的同一对象.一旦服务器保持活动结束并且套接字关闭,您将点击此按钮.