python
network_error
ai_generated
true
aiohttp 客户端异常:超过 30 次重定向
aiohttp.client_exceptions.TooManyRedirects: Exceeded 30 redirects
ID: python/aiohttp-client-connector-http-redirect-error
80%修复率
82%置信度
0证据数
2026-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
根因分析
服务器在循环中重定向客户端或重定向次数过多,超过了默认重定向限制。
English
The server is redirecting the client in a loop or too many times, exceeding the default redirect limit.
解决方案
-
85% 成功率 Set max_redirects to a reasonable limit and handle redirect loops
async with session.get(url, max_redirects=5) as resp: # process response -
80% 成功率 Disable automatic redirects and handle manually with loop detection
async with session.get(url, allow_redirects=False) as resp: if resp.status in (301, 302): new_url = resp.headers['Location'] # check for loop before following
无效尝试
常见但无效的做法:
-
Increasing the max redirects to a very high number
50% 失败
This may cause infinite loops or resource exhaustion.
-
Following redirects manually without checking for loops
60% 失败
Manual following may still get stuck in a redirect loop.