[{"data":1,"prerenderedAt":36},["ShallowReactive",2],{"blog:post:en:honor-retry-after-headers-scraping":3,"blog:related:en:honor-retry-after-headers-scraping":23},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":15,"thumbnail_url":16,"translations":17,"body":18,"asset_base":19,"checksum":20,"published_at":21,"content_updated_at":22},"honor-retry-after-headers-scraping","en","How to Honor Retry-After Headers When Scraping with Proxies","Parse Retry-After seconds and HTTP-date values in Python, keep per-proxy backoff state, and rotate IPs only when the wait is too long.","2026-11-27",[10,11,12,13,14],"rate-limiting","web-scraping","proxy-rotation","python","retry",[10,11,12,13,14],"https://blog-api.ro-proxy.com/api/blog/posts/honor-retry-after-headers-scraping/thumbnail.svg?lang=en",[5],"A 429 response is not a dead end. It is a schedule: the server tells you exactly when it will look at your traffic again, and most scrapers answer by retrying immediately or burning a fresh IP for no reason. Honoring Retry-After correctly — both formats, per exit IP, with rotation as the last resort — keeps your proxies useful and your scraper quiet.\n\n## What Retry-After actually tells you\n\nThe header appears on 429 (Too Many Requests) and 503 (Service Unavailable) responses, and sometimes on redirects. It comes in two forms:\n\n```\nRetry-After: 120\nRetry-After: Fri, 31 Jan 2026 15:30:00 GMT\n```\n\nThree things to remember:\n\n1. It is a minimum, not a promise. Add a small margin.\n2. It is usually scoped to that IP, path, or token, not your whole crawl.\n3. It is advice, not enforcement. Ignoring it is how a 429 becomes a ban.\n\nA 429 means \"you, specifically, too much\". A 503 with Retry-After means \"the server is saturated, everyone waits\". The parsing is identical; the diagnosis is not. If 503s appear across many paths and proxies, the problem is the target, not your pace.\n\n### Parse both formats, then schedule on a monotonic clock\n\nWall-clock time can jump (NTP, DST, suspend). Measure waits with time.monotonic and cap the delay so a malformed date cannot park your queue forever.\n\n```python\nimport time\nfrom datetime import datetime, timezone\nfrom email.utils import parsedate_to_datetime\n\ndef retry_after_seconds(response, default=60, cap=300):\n    raw = response.headers.get(\"Retry-After\")\n    if not raw:\n        return default\n    raw = raw.strip()\n    if raw.isdigit():\n        return min(int(raw), cap)\n    try:\n        until = parsedate_to_datetime(raw)\n        if until.tzinfo is None:\n            until = until.replace(tzinfo=timezone.utc)\n        wait = int((until - datetime.now(timezone.utc)).total_seconds())\n        return max(0, min(wait, cap))\n    except (ValueError, TypeError):\n        return default\n```\n\n## Configure the proxy and its rotation API\n\nEach proxy has its own username and password and connects through a gateway host on an HTTP port that carries both HTTP and HTTPS traffic; Pro and Business plans also get a SOCKS5 port. With RoProxy, the same proxy can run in sticky mode (keeps its IP until you rotate it or the IP fails) or timed mode (changes IP on your interval), and Pro and Business plans expose an endpoint that rotates the IP on demand, with a minimum wait between calls set by the plan.\n\n```python\nPROXIES = {\n    \"proxy-1\": \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\",\n    \"proxy-2\": \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\",\n}\nSOCKS5 = \"socks5h://USERNAME:PASSWORD@GATEWAY_HOST:SOCKS5_PORT\"\nROTATE_URL = \"https://backend-api.ro-proxy.com/api/session/SESSION_ID/rotate\"\nAUTH = {\"Authorization\": \"Bearer API_KEY\"}\n```\n\nUse the same proxy URL for http:// and https:// targets; the gateway handles both. On the Free plan the IP changes on a fixed schedule and cannot be rotated by hand, so the backoff logic below is the only lever you have.\n\n## Keep one backoff entry per exit IP\n\nRate limits are usually keyed to the exit IP, so your wait state must be too. Key it by proxy name, and clear the entry whenever that proxy's IP changes.\n\n```python\nimport time\nimport requests\n\nbackoff = {}  # proxy name -> monotonic time when it is free again\n\ndef wait_if_busy(name):\n    delta = backoff.get(name, 0.0) - time.monotonic()\n    if delta > 0:\n        time.sleep(delta)\n\ndef fetch(name, url):\n    proxy = {\"http\": PROXIES[name], \"https\": PROXIES[name]}\n    wait_if_busy(name)\n    r = requests.get(url, proxies=proxy, timeout=30)\n    if r.status_code in (429, 503):\n        delay = retry_after_seconds(r)\n        backoff[name] = time.monotonic() + delay\n        time.sleep(delay)\n        r = requests.get(url, proxies=proxy, timeout=30)\n    return r\n```\n\nRetry once after the wait. If the second attempt is also limited, store the new delay and let the caller decide; never loop silently.\n\n### A realistic sequence\n\n1. proxy-1 hits a 429 with Retry-After: 30. You sleep 30 seconds and retry; it succeeds.\n2. proxy-2 hits a 503 with an HTTP-date two minutes away. That entry blocks proxy-2 only.\n3. proxy-1 stays available the whole time, so the crawl keeps moving.\n4. A third 429 on proxy-1 asks for ten minutes. You rotate instead, clear the entry, and continue on the new IP.\n\n## Rotate only when the wait is too long\n\nShort waits are cheaper than a new IP. Sleep through anything under your threshold; only call the rotation endpoint when the server asks for more than you are willing to wait, because every rotation spends an IP you could have used later.\n\n```python\nROTATE_THRESHOLD = 120  # seconds\n\ndef fetch_or_rotate(name, session_id, url):\n    proxy = {\"http\": PROXIES[name], \"https\": PROXIES[name]}\n    wait_if_busy(name)\n    r = requests.get(url, proxies=proxy, timeout=30)\n    if r.status_code not in (429, 503):\n        return r\n    delay = retry_after_seconds(r)\n    if delay > ROTATE_THRESHOLD:\n        resp = requests.post(\n            ROTATE_URL.replace(\"SESSION_ID\", session_id),\n            headers=AUTH,\n            timeout=30,\n        )\n        if resp.ok:\n            backoff.pop(name, None)  # new exit IP, old limit no longer applies\n            return requests.get(url, proxies=proxy, timeout=30)\n    backoff[name] = time.monotonic() + delay\n    time.sleep(delay)\n    return requests.get(url, proxies=proxy, timeout=30)\n```\n\nThe rotation endpoint enforces a minimum wait between calls. If the call fails, fall through to the sleep path instead of retrying the call — spinning on it just adds errors.\n\n### Why not rotate on every 429\n\n- The limit may follow your account or token, not your IP, so a new IP changes nothing.\n- Sticky flows (login, cart, checkout) break when the IP changes mid-request.\n- Rapid IP churn is the pattern anti-bot systems score highest.\n\n## Verify the header yourself with cURL\n\n```bash\ncurl -s -D - -o /dev/null \\\n  -x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT \\\n  \"https://example.com/path\" | grep -i \"^retry-after\"\n\ncurl -s -x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT \\\n  https://api.ipify.org?format=json\n```\n\nThe first command shows what the server actually sends; the second confirms which exit IP the limit will be keyed to. If you see a date instead of a number, your parser must handle it — that is the case most scrapers miss.\n\n## Mistakes to avoid\n\n- Parsing only the integer form. HTTP-date values are common on 503s.\n- Sleeping on wall-clock time. Use a monotonic clock for scheduling.\n- Sharing one backoff across all proxies. Limits are per IP.\n- No cap on the wait. A bad date can stall the whole queue.\n- Rotating inside a sticky workflow. Finish the flow, then rotate.\n- Retrying the rotation endpoint when it rejects the call; the plan sets a minimum wait between calls.\n- Forgetting robots.txt crawl-delay. Retry-After and crawl-delay work together.\n\n## Conclusion\n\nTreat every 429 as a timestamp, not an insult: parse it, schedule it per exit IP, and rotate only when the wait outlasts your threshold. If you run RoProxy in sticky mode, the IP stays until you rotate it or it fails, so your backoff map stays honest; in timed mode, clear the entry whenever the interval fires. New accounts include free proxies to try this workflow, and support is on Telegram if you get stuck.\n","https://blog-api.ro-proxy.com/api/blog/posts/honor-retry-after-headers-scraping/assets","e4895e26a205db80486021b583b4ffefe37cdc92681669c338b506abd70870ea","2026-11-27T01:04:14.660817Z","2026-11-27T01:04:14.662576Z",[24,28,32],{"slug":25,"title":26,"summary":27},"proxy-aware-retry-queue-python","Building a Proxy-Aware Retry Queue in Python for Resilient Scraping","Learn how to implement a proxy-aware retry queue in Python that handles 429 and 503 responses with exponential backoff, jitter, and automatic proxy rotation for resilient web scraping.",{"slug":29,"title":30,"summary":31},"python-proxy-rotation-jitter-backoff","Proxy Rotation with Jitter and Exponential Backoff in Python","Adding jitter and exponential backoff to proxy rotation prevents rate-limit bans. This post covers Python code, RoProxy setup, and exit-IP checks.",{"slug":33,"title":34,"summary":35},"resume-large-downloads-rotating-proxies","Resume Large Downloads Through Rotating Proxies","Learn how HTTP Range requests let you resume interrupted downloads through rotating proxies, and why sticky rotation keeps each byte consistent.",1796251609228]