Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求的超时值是指接收到的第一个字节还是整个消息?_Python - Fatal编程技术网

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)