【发布时间】:2020-05-19 09:56:03
【问题描述】:
我正在尝试实现一种方法,该方法尝试尝试从 url 下载图像。为此,我使用 requests lib。我的代码示例是:
while attempts < nmr_attempts:
try:
attempts += 1
response = requests.get(self.basis_url, params=query_params, timeout=response_timeout)
except Exception as e:
pass
每次尝试花费的时间不能超过发出请求的“response_timeout”。但是似乎 timeout 变量没有做任何事情,因为它不尊重我自己给出的时间。
如何限制 response.get() 调用的最大阻塞时间。 提前致谢
【问题讨论】:
-
您为 response_timeout 设置的值是多少?
-
值为 1.5 秒。但是,如果我指定 0.1 秒,则响应时间完全相同。我想要的是在达到超时时抛出异常。独立地,如果请求完成与否。
标签: python python-3.x http python-requests