Python httplib ResponseNotReady

标签 python http rest 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

查看标题,我看到 ('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/

相关文章:

python - While 在服务器和客户端之间循环 (Python)

python - 单位球体表面区域上的点的随机样本

http - 无法从命令行访问 go 服务器/将 web 服务器逻辑添加到现有代码

Wordpress APIs 如何使用休息路线列出类别中的所有帖子

rest - 使用Grails中的Rest查找特定ID

python - 如何更改 matplotlib 在绘制时间戳对象时使用的步长?

python - 在不安装 Python 的情况下,在 Cloudera 虚拟机上安全地拥有两个版本的 Python

java - IP 地址的 App 引擎请求 header

ruby-on-rails - rails : get values of http response

rest - 如何使 Application Insights Rest Api 返回所有数据,即使它不存在?