Python requests proxy setup
How to send Python requests through VantixProxy: the proxy URL, rotating and sticky IPs, country targeting, SOCKS5, retries, and the errors you are most likely to meet.
- HTTP and SOCKS5
- Rotating or sticky IPs
- Login or IP whitelisting
Proxies for Python scripts
Lowest rate for each. Every tier is on the pricing page.
Before you start
Three things, and the whole guide takes about ten minutes.
Python and requests
Python 3 with the requests library: pip install requests. For SOCKS5, also install requests[socks].
Your proxy line
Copy it from the generator in your dashboard. The examples use the Eternal Residential format; for other products, paste the line the generator gives you.
A test address
https://api.ipify.org returns the IP a request came from, so you can see the proxy working. Our What is my IP tool does the same in a browser.
Step 1: Send a request through the proxy
Put the proxy URL in a proxies dictionary under both http and https, and pass it with every request. For https sites, requests opens an encrypted tunnel through the proxy, so the proxy never sees the page content. If you whitelisted your IP in the dashboard, drop the username and password from the URL.
- Scheme http://, even for https sites
- Login USERNAME:PASSWORD from the generator
- Host et.vantixproxy.com for Eternal Residential
- Port 1000 for Eternal Residential
Python: your first request (Eternal Residential format)
import requests
proxy = "http://USERNAME:[email protected]:1000"
proxies = {"http": proxy, "https": proxy}
r = requests.get("https://api.ipify.org", proxies=proxies, timeout=30)
print(r.text) # the proxy's IP, not yours
With IP whitelisting instead of a login
proxy = "http://et.vantixproxy.com:1000"
Step 2: Rotate or keep one IP
Without a session ID, every new connection gets a new IP. Add _session- with any ID to keep one IP, and _lifetime- with the minutes, up to 60, to say how long. Use a new ID when you want a new IP.
Rotating: a new IP on each call
import requests
proxy = "http://USERNAME:[email protected]:1000"
for _ in range(3):
print(requests.get("https://api.ipify.org", proxies={"http": proxy, "https": proxy}, timeout=30).text)
Sticky: one IP for 10 minutes
import requests, uuid
def sticky(minutes=10):
sid = uuid.uuid4().hex[:8]
url = f"http://USERNAME:PASSWORD_country-US_session-{sid}_lifetime-{minutes}@et.vantixproxy.com:1000"
return {"http": url, "https": url}
p = sticky()
for _ in range(3):
print(requests.get("https://api.ipify.org", proxies=p, timeout=30).text) # same IP
Step 3: Target a country or city
Add settings to the end of the password, each starting with an underscore. For a region or state, use _region- with the value shown in the generator.
| Setting | Example | What it does | Values |
|---|---|---|---|
| Country | _country-DE | Picks the exit country | 2-letter code |
| City | _city-new.york | Picks a city. Put it after the country | lowercase, dots |
| Session | _session-ab12cd34 | Keeps the same IP for every request with this ID | any ID |
| Lifetime | _lifetime-10 | How many minutes the session keeps its IP | up to 60 |
All four together: New York, one IP for 10 minutes
http://USERNAME:PASSWORD_country-US_city-new.york_session-ab12cd34_lifetime-10@et.vantixproxy.com:1000
Step 4: Use SOCKS5
Install the SOCKS extra, then change the scheme. Use socks5h:// rather than socks5:// so the proxy looks up the site’s address, and your own DNS server never sees it. Eternal Residential Lite is HTTP only; every other product speaks SOCKS5.
Install
pip install "requests[socks]"
Python: the same request over SOCKS5
import requests
proxy = "socks5h://USERNAME:[email protected]:1000"
r = requests.get("https://api.ipify.org", proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.text)
Step 5: Retry failed requests
Any network drops a request now and then. Let requests retry by itself, with a short pause that grows each time, on timeouts and on busy or error responses. Always set a timeout, so a slow request never hangs your script.
Python: a session that retries three times
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
proxy = "http://USERNAME:[email protected]:1000"
retry = Retry(total=3, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504])
s = requests.Session()
s.mount("http://", HTTPAdapter(max_retries=retry))
s.mount("https://", HTTPAdapter(max_retries=retry))
s.proxies = {"http": proxy, "https": proxy}
r = s.get("https://example.com", timeout=30)
print(r.status_code)
Troubleshooting and questions
Why do I get 407 Proxy Authentication Required?
The username or password is wrong, or the proxy expects your IP to be whitelisted. Copy the line again from the generator. If your password contains characters such as @, : or /, encode it first with urllib.parse.quote.
Why does my IP not change on every request?
Usually a requests.Session reusing one connection: an HTTPS connection through a proxy keeps the IP it started with. Use requests.get for each call, or a new Session for each IP you want. Also check the line has no _session ID.
Why am I getting SSL errors through the proxy?
Check that the proxy URL starts with http://, not https://, even for https sites. Keep certificate checks on rather than setting verify=False.
Can I set the proxy once for the whole script?
Yes. Set session.proxies on a requests.Session, or set the HTTP_PROXY and HTTPS_PROXY environment variables to the proxy URL. requests reads them for every call.
How do I use a product other than Eternal Residential?
Paste the line the dashboard generator gives you for that product. The targeting settings on this page are the Eternal Residential format; the generator writes the right format for every other product.
How do I check which country the proxy is in?
Open our What is my IP tool in a browser that uses the same proxy, or test your whole list with the free proxy checker.
Related guides and tools
Test your list, convert formats, or pick the right proxy for the job.
Get a proxy line for your script
Budget Residential from $0.49/GB, or Eternal Residential from $0.75/GB that never expires. No KYC, crypto or card.