python - 重试配置仅在方法中指定时有效,但在 Poolmanager 中指定时无效
问题描述
如果您希望所有请求都遵循相同的重试策略,您可以在 PoolManager 级别指定重试。
但如果我尝试:
import urllib3
http = urllib3.PoolManager(retries=False)
r = http.request("GET", "https://nghttp2.org/httpbin/redirect/4")
print(r.status)
我得到:
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='nghttp2.org', port=443): Max retries exceeded with url: https://nghttp2.org/httpbin/relative-redirect/1 (Caused by ResponseError('too many redirects'))
如果在方法中指定了重试,一切都会按预期进行:
import urllib3
from urllib3.util.retry import Retry
http = urllib3.PoolManager()
r = http.request("GET", "https://nghttp2.org/httpbin/redirect/4", retries=Retry(connect=5, read=2, redirect=5))
print(r.status)
蟒蛇 3.9.7,urllib 1.26.7
解决方案
推荐阅读
- javascript - 反应原生 - siganlR
- functional-programming - 如何在方案(N-queens)中从此函数中删除可变性
- python - 如何将用户的消息分配给 discord.py 中的变量?
- android - 有没有办法在兑换代码文本框android中以编程方式自动填充促销代码
- ruby-on-rails - 推送到 heroku 时出现“预编译资产失败”错误
- javascript - 使用 ajax 导入时如何访问较低级别的变量并连接它们
- discord.js - 从特定消息中删除特定成员的反应
- java - 在 Java 中发送 CSRF 身份验证 - Pusher
- r - 在 R 中绑定多个 csv 以输出到 ggplot2 中的图形
- authentication - 使用 GraphQL/HotChocolate 验证登录令牌