gpt4 book ai didi

Python请求模块连接超时

转载 作者:太空宇宙 更新时间:2023-11-03 10:47:18 25 4
gpt4 key购买 nike

我正在查看 http://docs.python-requests.org/en/latest/并且“连接超时”被列为一项功能。但是,当我进一步阅读时,它指出

timeout is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds).

这听起来不像是连接超时的描述。我看到的是连接成功,它上传了一个大文件,然后等待响应。但是,响应需要一段时间然后超时。

如何设置连接超时,但在连接成功后仍然等待缓慢的响应?多谢。

最佳答案

requests (for humans) 库有连接超时,见- https://requests.kennethreitz.org/en/master/user/advanced/#timeouts

r = requests.get('https://github.com', timeout=(3.05, 27))

# e.g. explicitly
conn_timeout = 6
read_timeout = 60
timeouts = (conn_timeout, read_timeout)
r = requests.get('https://github.com', timeout=timeouts)

文档并未明确说明元组中的哪个值是哪个值,但可以安全地假设它是 (connect, read) 超时。

关于Python请求模块连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24784665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com