# Retry-After header Python retry

> Copy a Retry-After header Python retry for HTTP 429 responses with bounded backoff and jitter.

Source: https://fullbytedeveloper.com/blog/retry-after-header-python
Keyword: BUCKET
Published here: 2026-11-25

I use this Retry-After header Python retry so you can wait. RFC 6585 defines 429 for rate limiting, and RFC 9110 permits `Retry-After` as seconds or an HTTP date [1] [2].

## Copy a Retry-After header Python retry

This standard-library example honors numeric `Retry-After`; when the header is absent or is a date, it uses bounded exponential backoff with jitter. Add date parsing if the API you call sends HTTP dates.

```python title="retry.py"
import random
import time
import urllib.request
from urllib.error import HTTPError


def get_with_429_retry(url, attempts=5, sleep=time.sleep):
    for attempt in range(attempts):
        try:
            return urllib.request.urlopen(url)
        except HTTPError as error:
            if error.code != 429 or attempt == attempts - 1:
                raise
            retry_after = error.headers.get("Retry-After")
            if retry_after and retry_after.isdigit():
                delay = float(retry_after)
            else:
                delay = min(60.0, 2.0 ** attempt) + random.uniform(0.0, 1.0)
            sleep(delay)
```

You should see the request return after the server's delay or a later backoff attempt.

## Handle 429 Too Many Requests

```bash
cd world2
python3 token_bucket.py
```

The level illustrates why retrying immediately keeps a rate limit exhausted [3]. Read [Claude Code context commands](/blog/claude-code-compact) and [agent tool deny rules](/blog/claude-code-deny-rules), or browse [Dev explainers](https://fullbytedeveloper.com/blog/topic/dev-explainers).

Real APIs define their own retry policy and headers. Use that API's documentation before choosing attempts, a maximum delay, or which requests are safe to repeat.

Send this to the friend debugging repeated 429 responses.

## Sources

1. [RFC 6585 section 4: 429 Too Many Requests](https://www.rfc-editor.org/rfc/rfc6585#section-4)
2. [RFC 9110 section 10.2.3: Retry-After](https://www.rfc-editor.org/rfc/rfc9110#section-10.2.3)
3. [ALGO ARCADE token-bucket example](https://github.com/kamilikamil/algo-arcade/blob/main/world2/token_bucket.py)
