Python中文
首页
教程
问答
标签
搜索
登录
注册
在python中如何挂起httppost请求?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>样本代码:</p> <pre><code>socket.setdefaulttimeout(150) MechBrowser = mechanize.Browser() Header = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 GTB7.1 (.NET CLR 3.5.30729)'} Url = "http://example.com" Data = "Justatest=whatever&letstry=doit" Request = urllib2.Request(Url, Data, Header) Response = MechBrowser.open(Request) Response.close() </code></pre> <p>我不认为上面的代码有什么问题,但偶尔我会挂起httppost请求,这会阻止整个脚本继续运行。我已经用了<code>socket.setdefaulttimeout(150)</code>怎么不起作用了?造成这个问题的原因是什么?我该怎么做才能摆脱这个?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>我想是因为你没有设置内容长度标题。如果一个请求被发布到服务器,数据将在请求的主体中提交。由于tcp连接基于流的特性,服务器无法找到请求的长度,除非您在头中明确地告诉它。在不知道请求何时结束的情况下,服务器必须无限期地等待。在</p> <p>timeout属性在这里不起作用,因为您的套接字在任何recv/send操作中都没有被阻塞。您已经完成了通过socket写入数据,但服务器认为您还有更多要发送的内容。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
在python3中使用Scipy pearsonr函数
4 回答
在Python3中使用scipy对多个lorentzian进行数据拟合
5 回答
在Python3中使用Script=argv
5 回答
在python3中使用selenium webdriver进行未解析的回溯
4 回答
在python3中使用selenium和phantomjs的网页截图之前如何等待?
4 回答
在Python3中使用Selenium和Requests模块从网页获取文件
3 回答
在python3中使用SIGINT终止函数
5 回答
在Python3中使用SIGTERM时,允许进程完成而不是中断
3 回答
在python3中使用smtplib发送XML内容
7 回答
在python3中使用socket库(RFCOMM模式)重新连接蓝牙设备?
5 回答
在python3中使用sounddevice和numpy编写wav文件
7 回答
在python3中使用Sqlalchemy插入MySQL查找类型错误的原因
4 回答
在python3中使用sqlite、pandas和sqlalchemy很难让rollback工作
5 回答
在python3中使用SQLite的FTS3/4
10 回答
在Python3中使用struct.calcsize()和len()有区别吗?
9 回答
在python3中使用substring函数时发生TypeError
6 回答
在Python3中使用Tkinter entry小部件写入串行设备
10 回答
在python3中使用tkinter时,如何在每次按下函数时获得运行该函数的按钮?
10 回答
在python3中使用tkinter的子帧
2 回答
在Python3中使用tryexcept块时,如何避免使用未初始化的变量?
10 回答