How to use proxies with Python Requests
Pass a proxies dict to Requests with the same URL for both keys: proxies = {"http": "http://USERNAME:PASSWORD@HOST:PORT", "https": "http://USERNAME:PASSWORD@HOST:PORT"}, then call requests.get(url, proxies=proxies). For SOCKS5, install requests[socks] and use socks5h://.
What you need
https key (so HTTPS traffic goes direct) and a https:// proxy scheme where http:// belongs.- An active CleanProxies plan: static ISP proxies for fixed US IPs, or rotating residential / mobile proxies for pools. The trial works too.
- Your credential line from the dashboard's proxy manager: host (or IP), port, username and password.
- Python 3.9 or later and
pip install requests. - For SOCKS5:
pip install "requests[socks]"(adds PySocks).
New to proxies? For the overview, read Using proxies with cURL, Python and Node.js and Proxies with Python Requests, Playwright and Puppeteer. This guide goes deeper on Python Requests only.
Your CleanProxies credentials
| Product | Line in your dashboard | Notes |
|---|---|---|
| Static ISP proxies | IP:PORT:USER:PASS | One line per dedicated IP. With IP whitelisting turned on, the line is just IP:PORT and no password is sent. |
| Rotating residential and mobile | HOST:PORT:USER:PASS | Generated in the proxy manager. The username carries the location and session you pick, so generate a new list to change them. |
Most tools want the same details as a URL: http://USERNAME:PASSWORD@HOST:PORT for HTTP(S) or socks5://USERNAME:PASSWORD@HOST:PORT for SOCKS5. The examples on this page use those placeholders; copy the host, port, username and password from your CleanProxies dashboard. To convert a whole list at once, paste it into the proxy list formatter.
How to set up CleanProxies in Python Requests
- 1
Install Requests
Runpip install requests(add"requests[socks]"if you plan to use SOCKS5). - 2
Build the proxy URL
Turn your dashboard line intohttp://USERNAME:PASSWORD@HOST:PORT. - 3
Set both keys
Use the same URL forhttpandhttps. The key is the scheme of the website you request, not of the proxy. - 4
Send a test request
Requesthttps://api.ipify.orgwith atimeoutand print the result.
Python Requests proxy example
import requests
proxy = "http://USERNAME:PASSWORD@HOST:PORT"
proxies = {"http": proxy, "https": proxy}
response = requests.get("https://api.ipify.org", proxies=proxies, timeout=30)
print(response.text) # the exit IP# pip install "requests[socks]"
import requests
proxy = "socks5h://USERNAME:PASSWORD@HOST:PORT"
proxies = {"http": proxy, "https": proxy}
print(requests.get("https://api.ipify.org", proxies=proxies, timeout=30).text)If the password has characters such as @, : or #, quote it first with urllib.parse.quote(password, safe="").
Use a Session for logged-in work
A Session keeps cookies and reuses connections, which is what you want on a static ISP proxy that holds one account's login. Set the proxy once on the session.
import requests
session = requests.Session()
session.proxies.update({
"http": "http://USERNAME:PASSWORD@HOST:PORT",
"https": "http://USERNAME:PASSWORD@HOST:PORT",
})
session.headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
session.get("https://example.com/login", timeout=30)Requests also honours HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables. A proxies argument wins over them, unless you disable trust_env on the session.
Rotate across a list of ISP proxies
Export your ISP proxies as IP:PORT:USER:PASS lines into proxies.txt and cycle through them.
import itertools
import requests
def to_url(line: str) -> str:
host, port, user, password = line.strip().split(":", 3)
return f"http://{user}:{password}@{host}:{port}"
with open("proxies.txt") as f:
pool = itertools.cycle([to_url(line) for line in f if line.strip()])
for url in ["https://api.ipify.org"] * 5:
proxy = next(pool)
r = requests.get(url, proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.text)Static ISP vs rotating residential in Python Requests
Static ISP proxies
Each ISP line is a 100% dedicated US IP on a real carrier ASN that never rotates while you hold it. Pair one line with one Session per account so logins always come from the same address.
Rotating residential proxies
With a rotating line, each new connection gets a fresh residential IP, but a Session reuses connections. Use plain requests.get (or a new Session) per request to rotate, and a sticky line with one Session for multi-step flows.
Verify your exit IP
The first example prints the exit IP. To see the headers a website receives as well, request https://httpbin.org/headers through the same proxies dict.
Open What is my IP? through the proxy to see the address and headers a website receives, or paste up to ten lines into the free proxy checker to test connectivity, latency and exit IP before you start.
Troubleshooting Python Requests proxy errors
| Problem | Likely cause | Fix |
|---|---|---|
| ProxyError: 407 Proxy Authentication Required | Wrong credentials, or special characters in the password breaking the URL. | Copy the line again and URL-encode the password. |
| Your real IP shows for HTTPS URLs | Only the http key is set. | Set both http and https to the proxy URL. |
| SSLError: wrong version number | The proxy URL starts with https://. | Use http:// for the proxy; HTTPS sites still tunnel securely. |
| ConnectTimeout / ReadTimeout | Wrong port, blocked outbound traffic, or no timeout set on a slow target. | Check the line with curl -x, always pass timeout=, and retry with backoff. |
| Missing dependencies for SOCKS support | PySocks isn't installed. | pip install "requests[socks]", then use socks5h://. |
Still stuck? Our 24/7 support team answers fast: contact us with the error and the line you used (leave the password out).
Python Requests proxy FAQs
Requests picks the proxy by the scheme of the URL you request. Without an https key, every HTTPS request skips the proxy and goes out from your own IP.