Proxy guide

How to Rotate Proxies in Python

This example sends an HTTPS request through a proxy selected by the Proxy11 Python SDK. The SDK rotates your local candidate list; it does not guarantee that a public proxy is online or suitable for every destination.

SDKs

Example

pip install proxy11 requests
import os
import requests
from proxy11 import ProxyClient

client = ProxyClient(os.environ["PROXY11_API_KEY"])
session = client.session(country="us", proxy_type="anonymous")

try:
    response = session.get("https://httpbin.org/ip", timeout=(5, 15))
except requests.exceptions.ProxyError:
    # The failed proxy is removed from the pool; retry once with the next one.
    response = session.get("https://httpbin.org/ip", timeout=(5, 15))
response.raise_for_status()
print(response.json())

Practical Tips

  • Set PROXY11_API_KEY in your environment; do not commit the key or paste it into shared logs.
  • The SDK session removes a proxy after a ProxyError and raises the error. Retry deliberately if your job should continue with the next candidate.
  • A destination 403 or 429 is the destination's response, not proof that the proxy is dead.

What the session rotates

The SDK selects an ip:port from a fetched list before each request. With auto-refresh enabled by client.session(), it fetches another batch when the current pool is exhausted. Requests already in progress are not moved to a different proxy.

Treat public proxies as unreliable

The API's speed is the checker's observed response time, not a promise about your target site. Use bounded timeouts, handle proxy connection errors, and avoid sending passwords, payment data, or other sensitive information through public proxies.


Proxy API

Fetch proxy lists in TXT, JSON, CSV, or XML formats.

API documentation

Python SDK

Install with pip and use rotators or requests sessions.

Python GitHub repo

Node.js SDK

Install with npm and use async proxy helpers.

Node.js GitHub repo