Rotating Datacenter Proxy in Python: requests and httpx
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.
Python requests: new IP per request versus one Session
# pip install requests
import requests
PROXY = "http://LOGIN:PASSWORD@HOST:PORT" # from My assets
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 assets. The first list should change from call to call in rotating mode; the second usually repeats because the Session reuses one connection.
# pip install httpx
import httpx
PROXY = "http://LOGIN:PASSWORD@HOST:PORT" # from My assets
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.
Some providers encode a session in the username. Proxy302 does it at generation time instead: on the rotating datacenter page, choose "Keep the same IP for about 10 minutes" instead of "New IP per connection". The IP then stays for about 10 minutes and changes after that, or after about 60 seconds without traffic.
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.
# 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.
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.
Billing is per GB from your wallet at US$0.40 per GB, with no traffic packs. Copy HOST, PORT, LOGIN and PASSWORD from My assets.
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 US IPs; the "one Session" list may repeat one.
Where datacenter IPs fit
This line has US exits only, and sites can recognise the addresses as datacenter addresses. It suits 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.
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 assets.
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 "Keep the same IP for about 10 minutes". It changes after about 10 minutes or about 60 seconds idle.
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?
US$0.40 per GB from the wallet, with no traffic packs. There is no free trial.
Product facts file of the site, checked 12 November 2026: rotating datacenter line, US exits only, US$0.40 per GB from the wallet, HTTP or SOCKS5, new IP on every new connection by default or the same IP for about 10 minutes (changes after about 10 minutes or about 60 seconds idle), no free trial.
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.
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.
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.
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.