python中requests请求超时 异常怎么书写
1个回答
展开全部
超时
你可以告诉 requests 在经过以 timeout 参数设定的秒数时间之后停止等待响应:
>>> requests.get('http://github.com', timeout=0.001)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
requests.exceptions.Timeout: HTTPConnectionPool(host='github.com', port=80): Request timed out. (timeout=0.001)
用异常处理获取超时异常就可以了,给你个例子,自己修改既可以
try:
requests.get('https://www.taobao.com/', timeout=0.1)
except requests.exceptions.ConnectTimeout:
NETWORK_STATUS = False
except requests.exceptions.Timeout:
REQUEST_TIMEOUT = TRUE
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询