gpt4 book ai didi

python - ResponseNotReady 用于真正简单的 python http 请求?

转载 作者:可可西里 更新时间:2023-11-01 17:13:39 35 4
gpt4 key购买 nike

我正在用 python 写一个简单的脚本到 replay saved HTTP requests .

这是脚本:

import httplib

requestFileName = 'C:/Users/Owner/request.txt'
connectionURL = 'localhost:4059'

requestFile = open(requestFileName,'r')

connection = httplib.HTTPConnection(connectionURL)
connection.send(requestFile.read())

response = connection.getresponse()
print response.status + " " + response.reason

connection.close()

这里是request.txt:

POST /ipn/handler.ashx?inst=272&msgType=result HTTP/1.0
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: mysite.com
Content-Length: 28
User-Agent: AGENT/1.0 (UserAgent)

region=website&compName=ACTL

当我运行这个脚本时,我得到这个错误信息:

Traceback (most recent call last):
File "C:/Users/Owner/doHttpRequest.py", line 11, in <module>
response = connection.getresponse()
File "C:\Python27\lib\httplib.py", line 1015, in getresponse
raise ResponseNotReady()
ResponseNotReady

但是,我的服务器可以正常接收请求。我可以使用调试器检查服务器代码,并查看请求是否已正确传输,包括所有 header 。

为什么我的脚本显示 ResponseNotReady?这不是一个大问题,因为我的脚本执行其主要任务(重播保存的 http 请求),但我希望能够使用脚本输出一些基本信息,例如状态代码,或者保存在某处响应

最佳答案

HTTPConnection.send 用于发送 HTTP 请求的数据部分。因此,您应该只提供请求文件中的最后一行而不是整个内容。

如果你想按原样使用你的请求,你应该使用 socket 模块来代替与服务器的原始连接。

关于python - ResponseNotReady 用于真正简单的 python http 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8385281/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com