Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.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_Python Requests - Fatal编程技术网

Python请求超时

Python请求超时,python,python-requests,Python,Python Requests,我一直在通读,以便更好地理解超时。基于此,我可以看到存在连接超时: connect_timeout = 0.0001 try: response = requests.get(url="https://httpbin.org/delay/5", timeout=(connect_timeout, 10.0)) except requests.exceptions.ConnectTimeout as e: print "Too sl

我一直在通读,以便更好地理解超时。基于此,我可以看到存在连接超时:

connect_timeout = 0.0001

try:
    response = requests.get(url="https://httpbin.org/delay/5",
                        timeout=(connect_timeout, 10.0))
except requests.exceptions.ConnectTimeout as e:
    print "Too slow Mojo!"
read_timeout = 1.0

try:
    response = requests.get(url="https://httpbin.org/delay/5",
                        timeout=(10.0, read_timeout))
except requests.exceptions.ReadTimeout as e:
    print "Waited too long between bytes."
并读取超时:

connect_timeout = 0.0001

try:
    response = requests.get(url="https://httpbin.org/delay/5",
                        timeout=(connect_timeout, 10.0))
except requests.exceptions.ConnectTimeout as e:
    print "Too slow Mojo!"
read_timeout = 1.0

try:
    response = requests.get(url="https://httpbin.org/delay/5",
                        timeout=(10.0, read_timeout))
except requests.exceptions.ReadTimeout as e:
    print "Waited too long between bytes."

如果响应未在特定时间内完成,我还希望请求模块“放弃”。我不确定这种超时的术语是什么。我将如何做到这一点?

您最后一句话的要求与您描述的第一种超时之间有什么区别?据我在博客文章中了解,连接超时是指客户端等待初始连接的时间,然而,我要求从连接完成后的初始请求到响应完成都有一个超时。请求库的可能副本不会为请求提供一个总超时。从一个请求开发者那里,他很好地解释了为什么请求没有总响应时间超时,以及它们的建议。