Respect Rate-Limit Headers

Hard ⏱ 18 min 33% acceptance ★★★★☆ 4.3
APIs answer 429 with a Retry-After header (seconds). Write polite_get(url) that GETs the URL; on 429 it sleeps for int(Retry-After) (defaulting to 1 if absent) and retries once; anything else follows the normal raise-or-return path.

Examples

Example 1
Input
polite_get(busy_url)
Output
parsed body after honoring Retry-After once
Explanation

The client backed off exactly as instructed.

Constraints

  • Only one retry.
  • Read the header via response.headers.get('Retry-After', '1').

Topics

APIsrate limiting

Companies

GitHubX CorpDiscord

Hints

Hint 1

Headers are strings — int() the value.

Hint 2

A small helper loop or straight-line code both work.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.