python
network_error
ai_generated
true
aiohttp.client_exceptions.TooManyRedirects: 0, message='Too many redirects', url=URL('https://example.com/loop')
ID: python/aiohttp-too-many-redirects
80%Fix Rate
86%Confidence
0Evidence
2024-08-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
The server returned more than max_redirects (default 10) redirect responses, often due to a redirect loop or cookie/auth misconfiguration.
generic中文
服务器返回了超过 max_redirects(默认 10)次重定向响应,通常由重定向循环或 cookie/认证配置错误引起。
Workarounds
-
90% success
Inspect the redirect chain with curl: curl -sIL https://example.com/loop | grep -i '^location'
-
85% success
Handle redirects manually to detect the loop: async with session.get(url, allow_redirects=False) as r: while r.status in (301, 302, 303, 307, 308): url = r.headers['Location'] r = await session.get(url, allow_redirects=False) -
82% success
Ensure cookies are sent (some redirect loops happen because auth cookie is missing): session.cookie_jar.update_cookies({'session': token})
Dead Ends
Common approaches that don't work:
-
70% fail
If it's a true loop, it will still hit 100 and fail.
-
50% fail
You now receive 3xx responses directly and must handle Location yourself.
-
90% fail
Unrelated to redirect count.