Python请求的超时值是指接收到的第一个字节还是整个消息?
文档()解释了Python请求的超时值是指接收到的第一个字节还是整个消息?,python,Python,文档()解释了timeout值,如下所示: 超时(浮点或元组)--(可选)等待服务器的时间 在放弃之前发送数据,以浮点或(连接超时,读取 超时)元组 这是指等待服务器发送单个字节,还是等待服务器发送“整个”消息?换句话说,是单个timeout值(不是元组),是read()调用的超时?如果将timeout指定为浮点数(不是元组),则这相当于将元组及其组件指定为相同的值: import requests try: response = requests.post('http://httpb
timeout
值,如下所示:
超时(浮点或元组)--(可选)等待服务器的时间
在放弃之前发送数据,以浮点或(连接超时,读取
超时)元组
这是指等待服务器发送单个字节,还是等待服务器发送“整个”消息?换句话说,是单个
timeout
值(不是元组),是read()
调用的超时?如果将timeout
指定为浮点数(不是元组),则这相当于将元组及其组件指定为相同的值:
import requests
try:
response = requests.post('http://httpbin.org/post', timeout=0.1)
except requests.exceptions.Timeout as e:
print(e)
如果设置timeout
非常小(0.001),则会得到ConnectTimeoutError
:
HTTPConnectionPool(host='httpbin.org', port=80): Max retries exceeded with url: /post (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x039970D0>, 'Connection to httpbin.org timed out. (connect timeout=0.001)'))
HTTPConnectionPool(host='httpbin.org', port=80): Max retries exceeded with url: /post (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x039970D0>, 'Connection to httpbin.org timed out. (connect timeout=0.001)'))
HTTPConnectionPool(host='httpbin.org', port=80): Read timed out. (read timeout=0.1)