# requests.exceptions.TooManyRedirects: Exceeded 30 redirects while fetching 'https://redirect.example.com'

- **ID:** `python/requests-connectionerror-too-many-redirects`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The server is redirecting the client in a loop or too many times.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **Manually handle redirects by inspecting the Location header** (85% success)
   ```
   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
   ```
2. **Use a session with a custom redirect handler to detect loops** (80% success)
   ```
   from requests import Session
s = Session()
s.max_redirects = 10
response = s.get('https://redirect.example.com')
   ```

## Dead Ends

- **Disabling redirects entirely** — May miss the final target if redirects are legitimate. (70% fail)
- **Increasing the maximum redirect limit arbitrarily** — If it's a loop, increasing limit does not help; it will still exceed. (80% fail)
