Python Requests integration

Proxies for Python Requests

Requests takes a proxy per URL scheme in its proxies argument, with the username and password inside the proxy URL. Point both at gate.proxyhat.com for residential or mobile IPs in the country you choose: rotating, sticky, or over SOCKS5.

Residential proxies
HTTP and SOCKS5 Code tested on our gateway Traffic never expires

What teams use Requests with proxies for

Public data collection

Load public pages, such as prices, listings and search results, the way a visitor in that country sees them.

Localization and ad checks

Check that geo-targeted pages, translations and ads render correctly in each market, from a residential or mobile connection there.

APIs and pages without a browser

Fetch pages that render without JavaScript, and public APIs, for a fraction of the traffic a browser uses.

Connection details

Hostgate.proxyhat.com
SOCKS5 port1080
HTTP port8080
AuthenticationUsername and password from the Proxies page of your dashboard
Username for one workerUSERNAME-country-US-sid-a3f8c20d1e-ttl-30m

Everything after your username is a flag: -country-US picks the exit country, -type-mobile the mobile carrier pool, -sid-… keeps one IP and -ttl-30m sets for how long (up to 24 hours). Leave out -type-mobile for residential IPs.

Need another proxy format? Proxy format converter →

Python Requests proxy code

Replace USERNAME and PASSWORD with the proxy credentials from the Proxies page of your dashboard and run with Python 3 after pip install -U requests. The SOCKS5 sample also needs the socks extra.

import requests

# No -sid-: every new connection can exit from a new IP.
proxy = "http://USERNAME-country-US:PASSWORD@gate.proxyhat.com:8080"
proxies = {"http": proxy, "https": proxy}

r = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(r.json())

Set both keys: the http entry is used for http:// URLs and the https entry for https:// URLs, and both point at the same HTTP gateway port. For HTTPS sites Requests opens a CONNECT tunnel, so the page itself stays encrypted end to end. Without -sid-, every new connection can exit from a new IP.

Tested on November 29, 2026 against gate.proxyhat.com with Requests 2.34.2 and PySocks 1.7.1 on Python 3.13: every sample printed a US IP, the sticky sample the same IP twice.

Checked against: Requests: proxies, Requests: SOCKS · checked November 29, 2026

Managing proxies from code? The ProxyHat SDK for Python, Node.js and Go creates sub-users with their own traffic limits, lists locations and reads usage; the proxy connection itself stays as above. SDK docs →

Rotating, sticky or no rotation

The session type is part of the username. Your code stays the same; only the login string changes.

Rotating

No session ID: each new connection can exit from a different IP. Good for many independent page loads.

USERNAME-country-US

Sticky

Add -sid- with 10 random hex characters and a -ttl-: the IP holds for that long (10m, 30m, 1h, up to 24h). Use it for multi-page flows that should stay on one address.

USERNAME-country-US-sid-a3f8c20d1e-ttl-30m

No rotation

Add -sid- with -norotate-true and no -ttl-: the IP doesn’t rotate on a timer and stays until you switch to a new sid.

USERNAME-country-US-sid-a3f8c20d1e-norotate-true

One sid holds one exit IP and handles about 4–5 connections at a time, so give every worker or browser its own sid. Sticky sessions last up to 24 hours. Add -type-mobile for 4G/5G carrier IPs; leave it out for residential.

Proxy errors and what they mean

407 Proxy Authentication RequiredThe gateway didn’t accept the login: the username or password is wrong, or the username format is (a typo in a flag such as -country-US). Copy both from the Proxies page of your dashboard and make sure the auth step runs before the first page load.
402 Payment RequiredThe traffic balance is used up, or the sub-user has reached its traffic limit. Top up or raise the limit in the dashboard; traffic you buy never expires.
ERR_TUNNEL_CONNECTION_FAILEDChrome’s name for a proxy that refused the connection, and it can hide a 402 or another gateway status. Send the same username and password through curl -x http://gate.proxyhat.com:8080 to see the real code.
ERR_PROXY_CONNECTION_FAILEDChrome couldn’t reach the gateway at all. Check the host and port (gate.proxyhat.com, 8080 for HTTP) and that your network allows outgoing connections to it.

All gateway errors and username flags are in the documentation: ProxyHat docs →

Price

Mobile and residential traffic share one price and one balance: from $4.00/GB for a 1 GB pack down to $1.80/GB for 1,000 GB. Traffic never expires, and all your workers draw from the same balance. See pricing →

Python Requests proxy setup: FAQ

Why set both http and https in proxies?

Requests picks the proxy by the scheme of the URL you request. With only an http key, https:// URLs skip the proxy and go out from your own IP.

socks5:// or socks5h://?

socks5h://. With socks5://, your machine resolves the hostname before connecting; with socks5h://, the proxy resolves it. HTTP on port 8080 needs no extra package and works the same for HTTPS sites.

How do I keep one IP across requests?

Put a sid in the username, as in the sticky sample: the IP holds for the -ttl- you set, up to 24 hours. For an IP that doesn’t rotate on a timer, use -sid- with -norotate-true and no -ttl-.

How do I run many requests in parallel?

Requests is synchronous. Run several workers in threads, each with its own sid (a sid handles about 4–5 connections at a time), or use an async client with the same proxy URL. Our concurrency guide, linked below, shows both patterns.

How do I pick a country, state or city?

Add -country- with a two-letter code (residential IPs in 195+ countries). For a state or city, add -region- and then -city- with their location codes, for example -country-US-region-new_york-city-new_york_city: the region must come before the city. -type-mobile switches to 4G/5G carrier IPs (150+ countries) at the same price.

What do 407 and 402 look like in Requests?

For https:// URLs, Requests raises ProxyError with Tunnel connection failed and the status: 407 Proxy Authentication Required means the gateway didn’t accept the login, 402 Payment Required that the traffic balance or the sub-user’s limit is used up. The errors table above has the details.

What is the ProxyHat Python SDK for?

It manages your account from Python: it creates sub-users with their own traffic limits, lists locations and reads usage. The proxy connection itself is plain Requests, as above. The Python SDK is in pre-release and installs from GitHub; see the SDK docs.

Run Python Requests through residential IPs

Create an account, buy a small pack and run the samples above before you scale out.

Pay as you go · Traffic never expires · Crypto checkout