python
network_error
ai_generated
true
requests.exceptions.TooManyRedirects: Exceeded 30 redirects while fetching 'https://redirect.example.com'
ID: python/requests-connectionerror-too-many-redirects
80%Fix Rate
87%Confidence
0Evidence
2025-09-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
The server is redirecting the client in a loop or too many times.
generic中文
服务器在循环中重定向客户端或重定向次数过多。
Workarounds
-
85% success Manually handle redirects by inspecting the Location header
response = requests.get('https://redirect.example.com', allow_redirects=False) while response.is_redirect: next_url = response.headers['Location'] response = requests.get(next_url, allow_redirects=False) if response.status_code == 200: break -
80% success Use a session with a custom redirect handler to detect loops
from requests import Session s = Session() s.max_redirects = 10 response = s.get('https://redirect.example.com')
Dead Ends
Common approaches that don't work:
-
Disabling redirects entirely
70% fail
May miss the final target if redirects are legitimate.
-
Increasing the maximum redirect limit arbitrarily
80% fail
If it's a loop, increasing limit does not help; it will still exceed.