
429 Too Many Requests is the most cooperative error status on the web. Unlike
a 403, which tells you nothing, a 429 usually tells you exactly what you did
wrong and exactly when to come back. Most clients throw half of that away.
The header you are probably mis-parsing
Retry-After has two legal formats, and they are not interchangeable:
Retry-After: 120 # delta-seconds
Retry-After: Wed, 17 Nov 2026 08:30:00 GMT # HTTP-dateA great deal of client code does int(response.headers["Retry-After"]), catches
the ValueError on the date form, and falls back to a default. The result is
that your carefully tuned backoff silently stops applying against every server
that sends a date — which is a meaningful share of them.
from email.utils import parsedate_to_datetime
from datetime import datetime, timezone
def retry_after_seconds(response, default=60, cap=3600):
raw = response.headers.get("Retry-After")
if not raw:
return default
raw = raw.strip()
if raw.isdigit():
return min(int(raw), cap)
try:
when = parsedate_to_datetime(raw)
if when.tzinfo is None:
when = when.replace(tzinfo=timezone.utc)
delta = (when - datetime.now(timezone.utc)).total_seconds()
return min(max(delta, 0), cap)
except (TypeError, ValueError):
return defaultThe cap matters. Some servers return a Retry-After of several days during an
incident. Without a ceiling, a worker takes that literally and your queue stalls
until someone notices.
Rate-limit headers worth reading
Many APIs publish their budget before you exhaust it. There is no single standard, but three families cover most of what you will meet:
| Header | Meaning |
|---|---|
RateLimit-Limit / RateLimit-Remaining / RateLimit-Reset | The IETF draft form. Reset is seconds from now. |
X-RateLimit-Limit / X-RateLimit-Remaining / X-RateLimit-Reset | The widely deployed earlier convention. Reset is often a Unix timestamp. |
RateLimit | The newer combined form, e.g. limit=100, remaining=12, reset=30. |
The trap is Reset: seconds-from-now in one family, absolute Unix time in the
other. A client that assumes the wrong one either hammers immediately or sleeps
for fifty-six years. Branch on magnitude — anything above about 10^9 is a
timestamp.
Read RateLimit-Remaining on successful responses and slow down before you
are refused. Backing off only after a 429 means you are always discovering
the limit by crossing it.
Backoff that is actually correct
Exponential backoff without jitter re-synchronises your workers. Ten workers
that all get a 429 at the same moment will all wake at the same moment, and
you will be rate-limited again immediately, forever.
import random, time
def backoff_delay(attempt, base=1.0, cap=60.0):
"""Full jitter: uniform over [0, exponential bound]."""
bound = min(cap, base * (2 ** attempt))
return random.uniform(0, bound)
def fetch_with_retries(session, url, max_attempts=5):
for attempt in range(max_attempts):
response = session.get(url)
if response.status_code != 429:
return response
wait = retry_after_seconds(response, default=backoff_delay(attempt))
time.sleep(wait)
raise RuntimeError(f"still rate limited after {max_attempts} attempts")Two rules, both frequently broken:
Retry-Afterwins. If the server told you when to come back, your exponential curve is not a better guess.- Use full jitter, not "exponential plus a little noise". Uniform over the whole interval is what decorrelates a fleet.
When a 429 is not about rate
Here is the part that catches scrapers. A 429 is sometimes an anti-bot
decision wearing a rate limit's clothes. The tell is that slowing down does not
help — you can drop to one request a minute and still get 429, because the
system is not counting your requests, it is judging your identity.
We learned the difference the expensive way. We built a warming strategy — establishing a session with ordinary-looking browsing before fetching the target — to deal with rate-limit refusals, and tested it against Akamai-protected sites. It failed nine out of nine. The refusal was never about the shape of our traffic. It was about where it came from, which no amount of pacing changes.
So when a 429 does not respond to backoff, treat it as a 403 and check:
- the exit address and its reputation
- whether a different country behaves differently
- whether the TLS handshake matches the
User-Agentyou are sending
The lever that worked for us was rotating the exit country, not just slowing down.
Check the body before you trust the status. We run a content guard across every
401, 403 and 429, because a short body on a 429 is a block page and a
long one usually is not. Classifying on the status line alone produces both
false positives and false negatives.
Avoiding the 429 in the first place
Concurrency is what actually produces rate limits, not total volume. A hundred requests spread across a minute is invisible; a hundred at once is a spike.
import asyncio
async def fetch_all(urls, limit=5):
semaphore = asyncio.Semaphore(limit)
async def one(url):
async with semaphore:
return await fetch(url)
return await asyncio.gather(*(one(u) for u in urls))Start the semaphore low and raise it while watching RateLimit-Remaining. For
large jobs, send the work asynchronously and collect results by job ID instead
of holding connections open:
curl -X POST "https://api.scrapengine.io/api/v1/scrape" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/page",
"async": true,
"render": true
}'That returns a job ID immediately; collect it from GET /scrape/{jobId}, or set
an x-callback-url header and receive a webhook when it finishes. Either way
the pacing stops being your problem.
Frequently asked questions
The server is refusing because you have sent too many requests in a given window. Unlike most refusals it is usually accompanied by a Retry-After header telling you exactly when to try again.
Related guides
- HTTP7 min read403 Forbidden: Why a Scraper Gets One and What Actually Fixes ItWe audited every 403 in our production corpus. The browser fingerprint was almost never the cause — the exit address was. Here is how to tell which one you have.
- HTTP7 min read503 Service Unavailable: What It Means and How to Get the Page AnywayA 503 can mean a server is overloaded, in maintenance, or quietly refusing you. Here is how to tell the three apart, and what to do about each.
- AI Agents7 min readHTML to Markdown: Turning a Live Page into Clean Input for an LLMConverting HTML to Markdown is easy. Getting Markdown worth feeding to a model is the hard part — most of the work happens before the converter runs.