Skip to content
Python HTTP library

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

Requests is the most common way to start scraping and monitoring in Python. The two mistakes behind most proxy issues are a missing 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

Every CleanProxies product works over HTTP(S) and SOCKS5. This is what the dashboard gives you.
ProductLine in your dashboardNotes
Static ISP proxiesIP:PORT:USER:PASSOne line per dedicated IP. With IP whitelisting turned on, the line is just IP:PORT and no password is sent.
Rotating residential and mobileHOST:PORT:USER:PASSGenerated 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. 1

    Install Requests

    Run pip install requests (add "requests[socks]" if you plan to use SOCKS5).
  2. 2

    Build the proxy URL

    Turn your dashboard line into http://USERNAME:PASSWORD@HOST:PORT.
  3. 3

    Set both keys

    Use the same URL for http and https. The key is the scheme of the website you request, not of the proxy.
  4. 4

    Send a test request

    Request https://api.ipify.org with a timeout and print the result.

Python Requests proxy example

HTTP(S) proxyPython
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
SOCKS5 with remote DNSPython
# 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.

Session with a proxyPython
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.

Round-robin rotationPython
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

Both products use the same setup. What changes is how long an IP stays with you.

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.

Static ISP ProxiesAs low as $0.75/IP

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.

Rotating Residential ProxiesAs low as $0.63/GB

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

ProblemLikely causeFix
ProxyError: 407 Proxy Authentication RequiredWrong 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 URLsOnly the http key is set.Set both http and https to the proxy URL.
SSLError: wrong version numberThe proxy URL starts with https://.Use http:// for the proxy; HTTPS sites still tunnel securely.
ConnectTimeout / ReadTimeoutWrong 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 supportPySocks 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.

Get CleanProxies for Python Requests

Super clean US ISP IPs from $0.75/IP with unlimited bandwidth, rotating residential from $0.63/GB and mobile from $0.79/GB. Instant delivery, 99.9% uptime and 24/7 support.