我一直在阅读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!"
并阅读超时:
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."
我也有兴趣拥有请求模块"放弃"如果响应未在特定时间内完成。我不确定这种超时的用语是什么。我将如何实现这一目标?