PY
Languages & HTTP Clients

Python Requests proxy

A Python Requests proxy is a Requests session that tunnels every HTTP and HTTPS call through an upstream proxy instead of the machine's public IP. Pass the Aethyn URL in username:password@host:port form on the proxies argument and each request exits from a real residential address.

Why a residential Python Requests proxy

Most of the web now scores datacenter ranges on sight: a script running from AWS, or from a single home connection in one country, either gets blocked or sees the wrong catalog, currency, and search results. Routing Requests through a residential proxy substitutes an ISP-assigned exit, so the destination treats the call as a consumer visit. Aethyn encodes country, city, and sticky-session targeting in the username, so the same proxies dict works for a one-off fetch and for a multi-step login. Rotation is the default — omit a session id and each requests.get() exits from a fresh IP. Add -session-<id>-lifetime-<minutes> when cookies or a cart must survive across calls. HTTPS needs no second endpoint: port 2099 tunnels CONNECT, so one URL covers both schemes. Timeouts belong on every call; residential paths are slower than datacenter, and an unbounded wait hides a dead exit as a hung worker.

Setup steps

  1. 1Install Requests with pip install requests.
  2. 2Grab your Aethyn username (aethyn-XXXXX) and password from the dashboard.
  3. 3Build the proxy URL and pass it to the proxies argument.
  4. 4Add targeting suffixes (e.g. -country-us) to the username as needed.

Code

Basic rotating request
import requests

proxy = "http://aethyn-XXXXX:PASSWORD@proxy.aethyn.io:2099"
proxies = {"http": proxy, "https": proxy}

resp = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(resp.json())  # each call exits from a fresh residential IP
Country targeting + sticky session
import requests

# US exit held for ~10 minutes via a sticky session id
user = "aethyn-XXXXX-country-us-session-abc123-lifetime-10"
proxy = f"http://{user}:PASSWORD@proxy.aethyn.io:2099"
proxies = {"http": proxy, "https": proxy}

resp = requests.get("https://example.com", proxies=proxies, timeout=30)
print(resp.status_code)
SOCKS5 via PySocks
# pip install requests[socks]
import requests

proxy = "socks5h://aethyn-XXXXX:PASSWORD@proxy.aethyn.io:1099"
proxies = {"http": proxy, "https": proxy}

resp = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(resp.json())  # socks5h = remote DNS, no local leak
Timeouts and 407 handling
import requests
from requests.exceptions import ProxyError, Timeout

proxy = "http://aethyn-XXXXX:PASSWORD@proxy.aethyn.io:2099"
session = requests.Session()
session.proxies = {"http": proxy, "https": proxy}
session.timeout = 30

try:
    resp = session.get("https://httpbin.org/ip")
    resp.raise_for_status()
    print(resp.json())
except ProxyError as e:
    # 407 = bad username/password or targeting suffix on the wrong field
    print("proxy auth or tunnel failed:", e)
except Timeout:
    print("exit did not respond in 30s — retry on a fresh IP")

Replace aethyn-XXXXX and PASSWORD with your dashboard credentials. See the full targeting reference and protocol/port list. Or use the official proxy-builder-sdk to build targeting strings without hand-assembling usernames.

Troubleshooting

The three failures that show up first with a Python Requests proxy are 407 Proxy Authentication Required, hanging connects, and HTTPS errors that look like SSL problems. A 407 means the username or password is wrong, or a targeting suffix was pasted into the password field — rebuild the URL from the dashboard and confirm the -country- / -session- tokens sit on the username. Hanging connects almost always mean a missing timeout; set timeout=30 on the call or on the Session so a dead exit fails instead of blocking the worker. If HTTP works but HTTPS raises ProxyError or SSLError, the client is not sending CONNECT through the HTTP proxy port: use the same http:// URL for both keys in the proxies dict, not an https:// proxy URL. SOCKS5 (port 1099) needs requests[socks] installed; without PySocks, Requests will ignore a socks5:// URL or throw immediately.

Tips

  • Always set a timeout — residential routes are slower than datacenter.
  • Reuse a requests.Session() for connection pooling across many requests.
  • Use a sticky session when a flow spans multiple requests (login, checkout).
  • Prefer socks5h:// over socks5:// so DNS resolves at the proxy, not locally.

Python Requests proxy FAQ

How do I set a proxy in Python Requests?
Build an http://user:pass@proxy.aethyn.io:2099 URL and pass it as both the http and https keys of the proxies dict (or set them on a Session). The HTTP port tunnels HTTPS via CONNECT, so you do not need a second endpoint.
Do I need a different proxy for HTTPS?
No. The HTTP port (2099) handles HTTPS automatically via the CONNECT method, so the same proxy URL works for both http and https in the proxies dict.
How do I rotate IPs in Python Requests?
Aethyn rotates by default — every request without a session id gets a fresh exit. To hold an IP, add a -session-<id>-lifetime-<minutes> suffix to the username.
What does 407 Proxy Authentication Required mean?
The proxy rejected the credentials. Check that the username is aethyn-XXXXX plus any targeting suffixes, that the password matches the dashboard, and that you did not put country or session tokens on the password side of the URL.
Can I use SOCKS5 with Python Requests?
Yes. pip install requests[socks], then use socks5h://aethyn-XXXXX:PASSWORD@proxy.aethyn.io:1099. The h in socks5h tells Requests to resolve DNS through the proxy so the lookup does not leak your real location.

Ready to wire up Python (Requests)?

Get your credentials and route your first Python (Requests) request through residential IPs in minutes.

Docs, solutions & blog

Related integrations

All integrations