小编Ale*_*oom的帖子

如何使用请求库在 python 中测试重试尝试

我有以下内容:

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

retry_strategy = Retry(
    total=3,
    status_forcelist=[429, 500, 502, 503, 504],
    method_whitelist=["HEAD", "GET", "OPTIONS"]
)
adapter = HTTPAdapter(max_retries=retry_strategy)
http = requests.Session()
http.mount("https://", adapter)
http.mount("http://", adapter)

response = http.get("some_endpoint")
Run Code Online (Sandbox Code Playgroud)

如何有效地进行单元测试,让我重试 N 次(在本例中为 3 次)?

python python-unittest retry-logic

6
推荐指数
1
解决办法
2026
查看次数

标签 统计

python ×1

python-unittest ×1

retry-logic ×1