Search RU
Tasks / API / Rate limiting with Retry-After
Statement medium

Rate limiting with Retry-After

`fetch_json(client, path, sleep, attempts=3)` handles 429.

- `200` — return `json()`;
- `429` — read `Retry-After` (seconds) and call `sleep(seconds)`, then retry;
- any other status — `ApiError` with no retries;
- after `attempts` — `ApiError`.

`sleep` is passed in from outside: tests must not actually wait. Check the values
that `sleep` received.

apirate-limitretry
test_solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

Why is `sleep` passed as a parameter? What does that give the test besides speed?

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts