Python请求超时

2024-06-16 12:05:41 发布

您现在位置:Python中文网/ 问答频道 /正文

为了更好地理解超时,我一直在阅读http://www.mobify.com/blog/http-requests-are-hard/http://docs.python-requests.org/en/latest/api/#requests.request。基于此,我可以看到连接超时:

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!"

读超时:

^{pr2}$

我还对请求模块“放弃”感兴趣,如果响应没有在特定时间内完成。我不知道这种超时是什么意思。我该怎么做?在


Tags: orgcomapihttpdocswwwconnecttimeout