在python中将超时设置为http响应读取方法 [英] set timeout to http response read method in python

查看:99
本文介绍了在python中将超时设置为http响应读取方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python构建一个下载管理器来娱乐,有时与服务器的连接仍处于打开状态,但是服务器没有向我发送数据,因此(HTTPResponse的)读取方法会永远阻止我.例如,当我从本国境外的服务器下载资源时,就会出现带宽受限的情况.

I'm building a download manager in python for fun, and sometimes the connection to the server is still on but the server doesn't send me data, so read method (of HTTPResponse) block me forever. This happens, for example, when I download from a server, which located outside of my country, that limit the bandwidth to other countries.

如何设置读取方法的超时时间(例如2分钟)?

How can I set a timeout for the read method (2 minutes for example)?

谢谢,尼尔.

推荐答案

您必须在 HTTPConnection 初始化.

注意:如果您使用的是旧版本的Python,则可以安装 httplib2 ;许多人认为它是httplib的替代品,它确实支持

Note: in case you are using an older version of Python, then you can install httplib2; by many, it is considered a superior alternative to httplib, and it does supports timeout.
I've never used it, though, and I'm just reporting what documentation and blogs are saying.

这篇关于在python中将超时设置为http响应读取方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆