Skip to content

Updated

Rotating Datacenter Proxy in Python:
requests and httpx

  1. Rotating datacenter (US, per GB) is paused.
  2. For scraping billed per GB, use rotating residential (Budget line from US$1.50 per GB); for a fixed datacenter IP, use static datacenter IPs billed per IP (from US$0.25 for 1 day).
  3. The Python code works the same with any rotating proxy: it gives a new IP on each new connection, and requests.Session and httpx.Client reuse connections, so a pooled connection keeps its IP. To get a new IP per request, open a new Session or Client for each request; to keep one IP for a short task, use a sticky session or reuse one Client. Always set a timeout: requests has none by default and httpx stops after 5 seconds of inactivity.

Check it right after buyingExample output

curl -x http://USER:PASS@HOST:PORT https://ipinfo.io/json

ip
203.0.113.24
country
US
Matches the country you picked
Again
203.0.113.141 → 203.0.113.67 → 203.0.113.209
A rotating proxy gives a new exit each time
Example addresses (203.0.113.0/24), not real exits
01 / 12Why a Session keeps the same IP

Rotating datacenter (US, per GB) is paused. For scraping billed per GB, use rotating residential (Budget line from US$1.50 per GB); for a fixed datacenter IP, use static datacenter IPs billed per IP (from US$0.25 for 1 day). The code below works with any rotating proxy: why a Session keeps the same IP, how to get a new one, and how to hold one for a short task.

Why a Session keeps the same IP

A rotating datacenter endpoint chooses the exit IP when a connection opens. If your code keeps the connection open and reuses it, the IP does not change.

The Requests documentation says a Session uses urllib3 connection pooling, so several requests to the same host reuse the underlying TCP connection. HTTPX says the same about Client, while its top-level functions such as httpx.get establish a new connection for every request. That one difference decides when your IP changes.

What to use for each goal

What to use for each goal
Itemrequestshttpx
New IP on each requestNew Session per request (or requests.get)New Client per request (or httpx.get)
Same IP for several requestsOne Session, or a proxy in sticky modeOne Client, or a proxy in sticky mode
SOCKS5pip install "requests[socks]", use socks5h://pip install "httpx[socks]", use socks5://
Default timeoutNone: set one5 seconds of inactivity

Source: the Requests and HTTPX documentation, read 12 November 2026. requests.get() builds a throwaway Session for each call.

Python requests: new IP per request versus one Session

# pip install requests
import requests

PROXY = "http://LOGIN:PASSWORD@HOST:PORT"   # from My proxies
PROXIES = {"http": PROXY, "https": PROXY}
URL = "https://ipinfo.io/ip"

def ip_on_new_connection():
    # A fresh Session has an empty connection pool, so it opens a new connection.
    with requests.Session() as s:
        return s.get(URL, proxies=PROXIES, timeout=(5, 20)).text.strip()

print("new connection each time:", [ip_on_new_connection() for _ in range(5)])

with requests.Session() as s:
    print("one Session:", [s.get(URL, proxies=PROXIES, timeout=(5, 20)).text.strip() for _ in range(5)])

Example only: fill in HOST, PORT, LOGIN and PASSWORD from My proxies. The first list should change from call to call in rotating mode; the second usually repeats because the Session reuses one connection.

Python httpx: new Client versus one Client

# pip install httpx
import httpx

PROXY = "http://LOGIN:PASSWORD@HOST:PORT"   # from My proxies
URL = "https://ipinfo.io/ip"
TIMEOUT = httpx.Timeout(20.0, connect=10.0)

def ip_on_new_connection():
    # A new Client has its own empty connection pool.
    with httpx.Client(proxy=PROXY, timeout=TIMEOUT) as client:
        return client.get(URL).text.strip()

print("new connection each time:", [ip_on_new_connection() for _ in range(5)])

with httpx.Client(proxy=PROXY, timeout=TIMEOUT) as client:
    print("one Client:", [client.get(URL).text.strip() for _ in range(5)])

Example only. The same logic as above: a new Client opens a new connection, one Client reuses its connections.

Keep one IP for a short task

Some providers encode a session in the username. Proxy302 does it at generation time instead: on the rotating residential page, set a session (Budget line: 1 to 120 minutes of your choice) instead of a new IP per connection. The IP then stays for that time.

Pick sticky mode for a login, a multi-page flow or a download that must come from one address. The mode is chosen when you generate the proxy, so choose it before you click generate.

SOCKS5 with requests and httpx

# pip install "requests[socks]" "httpx[socks]"
import requests, httpx

PROXY = "socks5h://LOGIN:PASSWORD@HOST:PORT"      # requests: socks5h resolves names on the proxy
print(requests.get("https://ipinfo.io/ip", proxies={"http": PROXY, "https": PROXY}, timeout=(5, 20)).text)

PROXY_HTTPX = "socks5://LOGIN:PASSWORD@HOST:PORT"  # httpx accepts a socks5:// URL
with httpx.Client(proxy=PROXY_HTTPX, timeout=20.0) as client:
    print(client.get("https://ipinfo.io/ip").text)

Example only. Generate the proxy as SOCKS5 first; each IP asset has one protocol. requests with socks5 resolves names on your machine, socks5h on the proxy.

Retries and timeouts

import time
import httpx
import requests
from requests.adapters import HTTPAdapter
from urllib3.util import Retry

# requests: retry on a Session, as in the Requests documentation
s = requests.Session()
retries = Retry(total=3, backoff_factor=0.5, status_forcelist=[429, 502, 503, 504])
s.mount("https://", HTTPAdapter(max_retries=retries))

# httpx: a plain retry loop with a growing pause
def get_with_retry(client, url, tries=3):
    for n in range(tries):
        try:
            r = client.get(url)
            if r.status_code not in (429, 502, 503, 504):
                return r
        except httpx.TransportError:
            pass
        time.sleep(2 ** n)
    raise RuntimeError("gave up after %d tries" % tries)

Example only. Retry only what is safe to repeat, and pause between attempts. A retry on a rotating proxy may leave from a different IP.

Generate and test the proxy

  1. Step 1: Open the rotating residential page

    Choose the exit country and, if you want one IP for a while, a session length. One username and password works over HTTP and SOCKS5.

  2. Step 2: Generate and copy

    Billing is per GB from your wallet; the Budget line starts at US$1.50 per GB. Copy HOST, PORT, LOGIN and PASSWORD from My proxies.

  3. Step 3: Run the examples

    Paste the details into the requests or httpx example and run it.

    Expected result In rotating mode the "new connection" list shows different IPs; the "one Session" list may repeat one.

Where datacenter IPs fit

Sites can recognise datacenter addresses as such. They suit data collection, monitoring and API work that follows the target site's terms. For accounts, shops or ad accounts use residential or static ISP IPs instead.

Troubleshooting

The IP is the same every time

Check Are you using one Session or Client, or did you generate the proxy in sticky mode?

Fix Open a new Session or Client per request, or generate a proxy in "New IP per connection" mode.

Stop when If a new Client still returns one IP, test with curl -x to separate the code from the proxy.

Timeout errors

Check Look at which timeout fired (connect or read) and the target site's speed.

Fix Raise the read timeout a little, keep the connect timeout short, and add a retry with a pause.

Stop when A proxy that never connects: re-check HOST, PORT, LOGIN and PASSWORD in My proxies.

SOCKS errors such as missing dependencies

Check Check that you installed requests[socks] or httpx[socks], and that the proxy was generated as SOCKS5.

Fix Install the extra, use the right URL scheme, or generate an HTTP proxy.

FAQ

How do I get a new IP on every request with a rotating proxy in Python?

Open a new connection each time: a new requests.Session or httpx.Client per request, or requests.get and httpx.get, which do not reuse a pool. A Session or Client in a loop reuses the connection and keeps the IP.

Why does my Session return the same IP?

Because the Session reuses the TCP connection to the same host. Create a new Session per request, or use a proxy generated in "New IP per connection" mode and a fresh connection for each call.

Can I keep one IP for a few minutes?

Yes. Generate the proxy with a session (rotating residential Budget line: 1 to 120 minutes). It changes after the session ends.

Does this proxy work with SOCKS5 in Python?

Yes, if you generated it as SOCKS5. Install requests[socks] or httpx[socks] and use a socks5:// or socks5h:// URL.

How much does it cost?

Rotating datacenter (US, per GB) is paused. Rotating residential starts at US$1.50 per GB on the Budget line, and a static datacenter IP at US$0.25 for 1 day. There is no free trial.

Further reading

Setup guides Proxy302 publishes on GitHub on the same topic:

Reference links

5
  1. Proxy302 product facts and price list

    Product observation · Confirmed on:

    Product facts file of the site, checked 12 November 2026: rotating residential Budget line US$1.50 per GB, sessions of 1 to 120 minutes, datacenter per IP US$0.25 for 1 day, HTTP or SOCKS5, no free trial.

  2. Requests: Advanced Usage

    Official documentation · Confirmed on:

    Read 12 November 2026: a Session uses urllib3 connection pooling and reuses the TCP connection to the same host; SOCKS needs requests[socks]; socks5 resolves DNS on the client and socks5h on the proxy; no timeout unless set; retries via urllib3 Retry mounted on an HTTPAdapter.

  3. HTTPX: Proxies

    Official documentation · Confirmed on:

    Read 12 November 2026: the proxy parameter works on Client and top-level functions; credentials go in the URL userinfo; SOCKS needs httpx[socks] and a socks5:// URL.

  4. HTTPX: Clients

    Official documentation · Confirmed on:

    Read 12 November 2026: the top-level API establishes a new connection for every request; a Client uses connection pooling and can reuse one TCP connection.

  5. HTTPX: Timeouts

    Official documentation · Confirmed on:

    Read 12 November 2026: default is a TimeoutException after 5 seconds of network inactivity; connect, read, write and pool timeouts; httpx.Timeout(10.0, connect=60.0).

Ready to try it?

Create an account, top up once, then pick rotating residential, static ISP or datacenter IPs and have one running in your browser within minutes.