python
network_error
ai_generated
true
aiohttp.client_exceptions.TooManyRedirects: 0, message='Too many redirects', url=URL('https://example.com/')
ID: python/aiohttp-toomanyredirects
80%Fix Rate
83%Confidence
0Evidence
2024-09-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.9+ | active | — | — | — |
Root Cause
The server returns a redirect loop (or more than max_redirects hops), typically due to HTTP-to-HTTPS misconfiguration or cookie/session requirements.
generic中文
服务器返回重定向循环(或超过 max_redirects 跳数),通常由 HTTP 到 HTTPS 配置错误或 cookie/会话要求引起。
Workarounds
-
88% success
async with session.get(url, allow_redirects=False) as r: print(r.status, r.headers.get('Location')) # follow manually and correct the base URL or auth cookie -
75% success
session.cookie_jar.update_cookies({'session': token}) async with session.get(url) as r: ...
Dead Ends
Common approaches that don't work:
-
80% fail
A true redirect loop never terminates; raising the limit only delays the failure and wastes requests.
-
65% fail
You then receive the 3xx response body instead of the target content, so the fetch still fails functionally.