[{"data":1,"prerenderedAt":35},["ShallowReactive",2],{"blog:post:en:test-rate-limiter-with-rotating-proxies":3,"blog:related:en:test-rate-limiter-with-rotating-proxies":22},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":14,"thumbnail_url":15,"translations":16,"body":17,"asset_base":18,"checksum":19,"published_at":20,"content_updated_at":21},"test-rate-limiter-with-rotating-proxies","en","How to Test Your Rate Limiter with Rotating Proxies","Use a rotating proxy to exercise your own rate limiter: fill the bucket, assert 429 and Retry-After, rotate the IP, and confirm the counter resets.","2026-11-26",[10,11,12,13],"rate-limiting","testing","proxy-rotation","python",[10,11,12,13],"https://blog-api.ro-proxy.com/api/blog/posts/test-rate-limiter-with-rotating-proxies/thumbnail.svg?lang=en",[5],"Rate limiters fail quietly. You add the middleware, the happy path passes, and nobody learns that the counter is keyed on the wrong field, that the window never resets, or that a client can forge the header that picks the key — until a burst of real traffic hits.\n\nA rotating proxy gives you many source IPs without renting servers, and it lets you verify the behavior that matters most: a new IP gets a fresh bucket. Here is a repeatable way to test your own limiter end to end.\n\n## What \"working\" means\n\nPin the assertions before writing any code:\n\n1. Requests from one IP, up to the limit, return 200.\n2. The next request returns 429 with a Retry-After header.\n3. After the IP changes, the counter starts over.\n4. After the window elapses, the counter starts over even with the same IP.\n\nIf any of the four fails, the limiter is not doing what you think it does.\n\n## Why not test from localhost\n\nFrom localhost every request looks like 127.0.0.1, so an IP-keyed counter has nothing to count. You also cannot check that your edge really strips client-supplied X-Forwarded-For, because there is no edge in the path. Sending the request through a proxy puts a real peer address in front of your app and forces the same code path production uses.\n\n## Configure the proxy\n\nPoint the test client at the gateway. With RoProxy, each proxy has its own username and password, and one HTTP port carries both HTTP and HTTPS traffic; Pro and Business plans also expose a SOCKS5 port.\n\n```python\nPROXY = \"http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT\"\nPROXIES = {\"http\": PROXY, \"https\": PROXY}\n\n# Same gateway, SOCKS5 port, if your plan has one:\n# SOCKS = \"socks5://USERNAME:PASSWORD@GATEWAY_HOST:SOCKS5_PORT\"\n```\n\nThe socks5:// scheme needs the PySocks extra: pip install 'requests[socks]'.\n\nSet the proxy to sticky mode before you start. Sticky keeps the same IP until you rotate it or it fails, which is what you want while you fill a bucket. Timed mode changes the IP on its own schedule and makes the test flaky.\n\n## Step 1: Confirm the exit IP\n\n```python\nimport requests\n\ndef exit_ip():\n    r = requests.get(\n        \"https://api.ipify.org?format=json\",\n        proxies=PROXIES,\n        timeout=10,\n    )\n    r.raise_for_status()\n    return r.json()[\"ip\"]\n\nprint(exit_ip())\n```\n\nRun it twice. The same IP both times means sticky mode holds. If the IP moves, every counter assertion below is meaningless.\n\n## Step 2: Fill the bucket\n\nAim at a test route on your own service so you can read the real response.\n\n```python\nLIMIT = 10\nURL = \"https://your-app.example/limited\"\n\ndef hit():\n    return requests.get(URL, proxies=PROXIES, timeout=10)\n\ncodes = [hit().status_code for _ in range(LIMIT + 3)]\nprint(codes)\n```\n\nYou want the first LIMIT entries to be 200 and the rest to be 429. Then check the header:\n\n```python\nresp = hit()\nassert resp.status_code == 429\nassert int(resp.headers[\"Retry-After\"]) > 0\n```\n\n### Spoof the header on purpose\n\n```python\nr = requests.get(\n    URL,\n    proxies=PROXIES,\n    headers={\"X-Forwarded-For\": \"203.0.113.9\"},\n    timeout=10,\n)\nprint(r.status_code)\n```\n\nIf that request is counted as a brand-new client, your app trusts a header any caller can set. Your edge should overwrite it, and your limiter should key on the peer address the edge passes down.\n\n## Step 3: Rotate and confirm a fresh bucket\n\nOn the Pro and Business plans you can rotate on demand, and the API enforces a minimum wait between calls, so sleep between attempts or handle the error.\n\n```python\nimport time\n\nROTATE = \"https://backend-api.ro-proxy.com/api/session/SESSION_ID/rotate\"\n\ndef rotate():\n    r = requests.post(\n        ROTATE,\n        headers={\"Authorization\": \"Bearer API_KEY\"},\n        timeout=15,\n    )\n    r.raise_for_status()\n\nbefore = exit_ip()\nrotate()\ntime.sleep(2)\nafter = exit_ip()\n\nassert before != after, \"IP did not change\"\nassert hit().status_code == 200\n```\n\nOn the Free plan the IP changes on a fixed schedule and cannot be rotated by hand, so run the same two assertions after the next scheduled change instead.\n\n## Step 4: Wait out the window\n\nUse a short window on the test route, then confirm recovery without any rotation.\n\n```python\ntime.sleep(65)  # the test route uses a 60 second window\nassert hit().status_code == 200\n```\n\n### False positives that waste your morning\n\n- Trusted headers. If the app reads X-Forwarded-For from any client, a caller can pick their own counter key. The spoof test above catches this.\n- You measured the edge, not your code. If the 429 comes from a CDN or WAF, your limiter never ran. Compare response headers and body before you celebrate.\n- Shared IP. Other traffic on the same IP can fill the bucket, so a 429 on request two is a signal, not proof. Use a different proxy or a route with its own limit.\n- Client retries. A retry policy in the test client inflates the count. Disable retries while testing.\n- Mode drift. If the proxy is in timed mode, the IP can change mid-loop and your counts come from two buckets.\n\n### What this does not prove\n\n- Behavior under concurrency. One client fills one bucket. For more, list your proxies through the API and run one worker per proxy.\n- That your limit values are tuned correctly. The test proves the mechanism, not the numbers.\n- Anything about other people's services. This is for your own limiter.\n\n### Running it as a check, not a one-off\n\n- Point it at staging, not production, and keep LIMIT small.\n- Fail the build on any 429 before LIMIT, any missing Retry-After, or any 200 right after rotation.\n- Give each job its own proxy so parallel runs do not share a bucket.\n- Keep the request rate low; this is a correctness check, not a load test.\n\n### Keep it honest\n\nRun this only against services you own or have permission to test, and delete test routes when the experiment ends.\n\n## Wrap-up\n\nFill, assert 429, rotate, assert 200: four checks that turn rate limiting from a production surprise into a small script you can run before every release. On RoProxy the rotate call is a single POST with a bearer key, so the whole loop fits in one Python file.\n","https://blog-api.ro-proxy.com/api/blog/posts/test-rate-limiter-with-rotating-proxies/assets","7194ca2226514a5bc07820682090148e239eafa71559fd63c6272fd2d65bf86c","2026-11-26T01:07:59.497103Z","2026-11-26T01:07:59.500281Z",[23,27,31],{"slug":24,"title":25,"summary":26},"honor-retry-after-headers-scraping","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.",{"slug":28,"title":29,"summary":30},"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":32,"title":33,"summary":34},"implementing-proxy-aware-token-bucket-rate-limiter-python-distributed-scrapers","Implementing a Proxy‑Aware Token Bucket Rate Limiter in Python for Distributed Scrapers","Learn how to build a token‑bucket rate limiter that respects per‑proxy limits, integrates with rotating proxy pools, and keeps high‑throughput scrapers stable.",1796251609258]