Prompt

How do I set up rotating residential proxies in Python?

Latest observation

Jul 15, 2026 · OpenAI APIWeb search: off

To set up rotating residential proxies in Python, you usually need:

  1. A proxy provider that offers residential IPs and rotation
  2. A proxy endpoint, username/password, or API token
  3. Your Python HTTP client configured to send requests through the proxy

1) Get a residential proxy provider

Most residential proxy services give you one of these setups:

  • Single rotating gateway: one proxy host, IP changes automatically
  • Sticky sessions: same IP for a while using a session ID
  • Per-request rotation: each request can use a new IP

Typical info you’ll get:

  • Proxy host: proxy.provider.com
  • Port: 8000
  • Username: user
  • Password: pass

Sometimes the username includes options like country or session:

  • user-country-us-session-12345
  • or user|country=us|session=12345 depending on provider

2) Use it with requests

Basic example:

import requests

proxy = "http://user:pass@proxy.provider.com:8000"

proxies = {
    "http": proxy,
    "https": proxy,
}

response = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(response.text)

3) Rotate proxies

If your provider gives you a rotating gateway, you may not need to change anything—each request can come from a different IP automatically.

If you want to rotate manually across multiple proxy endpoints:

import requests
import itertools

proxy_list = [
    "http://user1:pass1@proxy1.provider.com:8000",
    "http://user2:pass2@proxy2.provider.com:8000",
    "http://user3:pass3@proxy3.provider.com:8000",
]

proxy_cycle = itertools.cycle(proxy_list)

for url in ["https://httpbin.org/ip"] * 5:
    proxy = next(proxy_cycle)
    proxies = {"http": proxy, "https": proxy}
    r = requests.get(url, proxies=proxies, timeout=30)
    print(r.json())

4) Sticky sessions

If you need the same residential IP for a short period, use a session identifier if your provider supports it.

Example pattern:

session_id = "abc123"

proxy = f"http://user-session-{session_id}:pass@proxy.provider.com:8000"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(r.text)

If you want a new IP later, change the session ID.

5) Use with aiohttp

For async requests:

import aiohttp
import asyncio

async def main():
    proxy = "http://user:pass@proxy.provider.com:8000"
    async with aiohttp.ClientSession() as session:
        async with session.get("https://httpbin.org/ip", proxy=proxy) as resp:
            print(await resp.text())

asyncio.run(main())

6) Best practices

  • Use HTTPS to protect credentials in transit
  • Set timeouts and retries
  • Rotate user-agent strings if appropriate
  • Respect target site terms and rate limits
  • Test for:
    • IP leakage
    • DNS leakage
    • proxy auth errors
    • blocked ports

Example with retries:

import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

session = requests.Session()

retries = Retry(
    total=3,
    backoff_factor=1,
    status_forcelist=[429, 500, 502, 503, 504],
)

session.mount("http://", HTTPAdapter(max_retries=retries))
session.mount("https://", HTTPAdapter(max_retries=retries))

proxy = "http://user:pass@proxy.provider.com:8000"
session.proxies.update({"http": proxy, "https": proxy})

r = session.get("https://httpbin.org/ip", timeout=30)
print(r.text)

7) Verify the proxy works

Test with a site that shows your public IP:

import requests

proxy = "http://user:pass@proxy.provider.com:8000"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(r.json())

If you want, I can also show:

  • a clean reusable proxy rotation helper class
  • an async version
  • or a setup for a specific provider like Bright Data, Oxylabs, Smartproxy, etc.

Observation history

Unlock observation history

Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.