问了一下 chatGPT ,感觉不对
如果你想设置 "连接超时时间" 和 "读取超时时间",可以通过将一个浮点数(表示秒数)或一个二元组(分别表示连接超时和读取超时)传递给 timeout 参数来实现:
import requests
# 设置连接和读取超时为 5 秒
response = requests.get("https://example.com", timeout=5)
# 设置连接超时为 3 秒,读取超时为 10 秒
response = requests.get("https://example.com", timeout=(3, 10))
更多的操作,你看看这篇文章https://www.cnblogs.com/gl1573/p/10129382.html
官网文档:
Timeouts
You can tell Requests to stop waiting for a response after a given number of seconds with the parameter. Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely:timeout
最后一句说不设置超时时间的可能会导致你的程序一直挂起。所以chatGPT说的应该是对的
1 回答9.7k 阅读✓ 已解决
2 回答5.5k 阅读✓ 已解决
2 回答3.7k 阅读✓ 已解决
3 回答4.6k 阅读
4 回答1.5k 阅读✓ 已解决
3 回答1.5k 阅读✓ 已解决
4 回答1.7k 阅读✓ 已解决
https://requests.readthedocs.io/en/latest/user/advanced/#time...
翻译一下: