Skip to content
Python Requests

Using our proxies with Python Requests

Requests takes proxies as a dictionary per request or per session. The sample below routes both http:// and https:// targets through one proxy and prints the exit IP.

Pick a proxy

Compatibility

  • Proxies are set with the proxies argument on any request method, or on a Session; the proxy URL must include the scheme.
  • Basic proxy authentication uses the http://user:password@host:port form in the proxy URL.
  • SOCKS proxies require the optional extra: pip install "requests[socks]"; socks5h:// resolves DNS on the proxy, socks5:// on the client.
  • Without an explicit proxies argument, Requests reads HTTP_PROXY, HTTPS_PROXY, NO_PROXY and ALL_PROXY from the environment.
Protocols:
HTTP, HTTPS (CONNECT), SOCKS5
Connection:
Username and password, IP allowlist

Configuration

import requests

# HTTP proxy for both http:// and https:// targets
proxy = "http://USERNAME:PASSWORD@PROXY_HOST:PORT"
# SOCKS5 (needs: pip install "requests[socks]"):
# proxy = "socks5h://USERNAME:PASSWORD@PROXY_HOST:PORT"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://api.ipify.org?format=json", proxies=proxies, timeout=30)
print(r.json())

Both keys of the dictionary point to the same HTTP proxy, so HTTPS targets are tunnelled through it. Swap in the commented socks5h:// line if we sent you a SOCKS5 endpoint. For IP allowlist access, remove USERNAME:PASSWORD@.

PROXY_HOST, PORT, USERNAME and PASSWORD are placeholders. After we select proxies for your task, we send you the real host, port and credentials.

Check the result

python -c "import requests; p='http://USERNAME:PASSWORD@PROXY_HOST:PORT'; print(requests.get('https://api.ipify.org?format=json', proxies={'http': p, 'https': p}, timeout=30).json())"
  1. Run the one-line test: the printed ip must be the exit IP we sent you.
  2. Look up the exit IP in two independent GeoIP services and confirm both show the country (and city, if you asked for one) from your request. GeoIP databases can disagree; tell us if they do.
  3. Request one page of your own site or a permitted source with the same proxies and check the status code and content for that country.

What to put in the request

  • Protocol: HTTP or SOCKS5, and whether DNS must be resolved by the proxy.
  • Access method: username/password, or the server IP for an allowlist.
  • Country (city only if the task needs it) and session mode: static, sticky or rotating.
  • Expected request volume per hour and number of parallel sessions.
  • The task: QA of your own site, monitoring, or a permitted public data source.

Common pitfalls

  • Setting session.proxies and expecting it to win: the Requests docs warn that environment proxies can override it. Pass proxies= on each request to be sure.
  • Forgetting the scheme in the proxy URL, or using socks5:// without installing requests[socks].
  • Disabling certificate verification to get past a TLS error. Fix the cause instead; verify=False exposes the connection to interception.

Recommended proxy types

Sources

Not sure which proxy fits?

Describe the task in two sentences. We reply with a concrete setup and price, usually within one business day.

Availability, exact parameters and price are confirmed in our reply after manual selection. Nothing is charged automatically.

Pick a proxy