如何在Python3请求中等待更少的连接超时



我有这样的东西以供请求错误例外:

try:
    r = requests.get(url, stream=True)
    r.raise_for_status()
except requests.exceptions.HTTPError as err:
    print("HTTP exception error: {}".format(err))
    return
except requests.exceptions.RequestException as e:
    print("Exception error {}".format(e))
    return

要获得这样的错误,我必须等待超过2分钟:

异常错误httpconnectionpool(host ='192.168.137.67',端口= 8000(: 最大检索超过了url:/python-3.4.3.msi(由 NewConnectionError(':未能建立新连接:[Errno 110] 连接时间超时',((

是否可以更快地获取超时错误?尝试一两次

timeout paramater:

r = requests.get(url, stream=True, timeout=10)

,如果请求比10 seconds

征用,这将引起异常

更多信息。

最新更新