NEW LOWER PRICES!All plans now up to 15% cheaper — Same trusted quality, same stability — just better pricing!
View Plans
Telegram

Python (requests, httpx, aiohttp)

Python proxy setup for requests, httpx and aiohttp: add auth and use a python rotating proxy with ready-to-run code examples.

Integrations6 min read

Setting up a Python proxy looks slightly different in each of the three most common HTTP clients (requests, httpx, and aiohttp), and the httpx API has changed (the old proxies= argument is gone; use proxy= or mounts=). The Python requests proxy pattern is a proxies dict, httpx takes a single proxy= client argument, and aiohttp sets the proxy per request. This page shows how to route each library through your ColdProxy gateway with username/password auth, including rotating vs. sticky sessions and the IP-whitelist alternative. For background on the auth models, see IP whitelisting vs. username/password.

Your ColdProxy connection details

  • Gateway host: gw-{service-id}.coldproxy.com — examples use gw-2312.coldproxy.com; replace 2312 with your service/package ID (a Use Hostname instead of IP toggle in the client area switches to a direct IP).
  • Port: any port in 30000-34999 (examples use 30000).
  • Protocols: HTTP, HTTPS (TCP) and SOCKS5 (TCP and UDP), auto-detected on the same ports.
  • Auth: username/password (HTTP Basic / SOCKS5 auth) or IP whitelist (up to 50 IPs).

The proxy string is gw-2312.coldproxy.com:PORT:USERNAME:PASSWORD, equivalent to USERNAME:[email protected]:PORT.

Note

After an order is delivered, wait about 10-20 minutes for the proxies to authenticate and activate. If your username or password contains reserved characters (@ : # % /), URL-encode them with urllib.parse.quote(value, safe="") before building the proxy URL.

Python requests proxy setup

Pass a proxies dict with both http and https keys pointing at the same ColdProxy endpoint. If you only set http, requests will send HTTPS traffic over your real IP, so always set both:

Python
import requests

proxy = "http://USERNAME:[email protected]:30000"
proxies = {"http": proxy, "https": proxy}

resp = requests.get("https://api.vipv6proxy.com/api/checker/my-ip", proxies=proxies, timeout=30)
print(resp.json())  # confirms the exit IP

SOCKS5 with requests

SOCKS5 support requires the PySocks extra. Install it, then use a socks5h:// URL so DNS resolves at the proxy (remote DNS):

Shell
pip install "requests[socks]"
Python
import requests

proxy = "socks5h://USERNAME:[email protected]:30000"
proxies = {"http": proxy, "https": proxy}

resp = requests.get("https://api.vipv6proxy.com/api/checker/my-ip", proxies=proxies, timeout=30)
print(resp.json())
Tip

Use socks5h:// (not socks5://) so the hostname is resolved from the proxy's location, avoiding DNS leaks. Background: SOCKS5 vs. HTTPS proxies and the SOCKS5 glossary entry.

httpx

httpx removed the old proxies= argument. For one proxy for all traffic, pass a single proxy= string to the client:

Python
import httpx

proxy = "http://USERNAME:[email protected]:30000"

with httpx.Client(proxy=proxy, timeout=30) as client:
    resp = client.get("https://api.vipv6proxy.com/api/checker/my-ip")
    print(resp.json())

Per-scheme routing with mounts

Use mounts= when you need different transports per scheme or want to exclude certain hosts. Each entry is an httpx.HTTPTransport(proxy=...):

Python
import httpx

proxy = "http://USERNAME:[email protected]:30000"
mounts = {
    "https://": httpx.HTTPTransport(proxy=proxy),
    "https://": httpx.HTTPTransport(proxy=proxy),
}

with httpx.Client(mounts=mounts, timeout=30) as client:
    resp = client.get("https://api.vipv6proxy.com/api/checker/my-ip")
    print(resp.json())

SOCKS5 with httpx

Install the socks extra, then pass a socks5h:// proxy URL:

Shell
pip install "httpx[socks]"
Python
import httpx

proxy = "socks5h://USERNAME:[email protected]:30000"

with httpx.Client(proxy=proxy, timeout=30) as client:
    resp = client.get("https://api.vipv6proxy.com/api/checker/my-ip")
    print(resp.json())

httpx accepts both socks5:// and socks5h:// and treats them identically: its SOCKS transport always sends the target hostname to the proxy, so DNS resolves remotely either way (unlike requests, where socks5:// resolves DNS locally). Using socks5h:// keeps your proxy URLs consistent with the cURL and requests examples.

Note

AsyncClient takes the same proxy=/mounts= arguments as Client, so the async versions are identical aside from async with and await client.get(...).

aiohttp proxy setup

aiohttp takes the proxy URL and credentials per request; its built-in support covers http:// proxy URLs (HTTPS targets are tunneled through them). Pass credentials as aiohttp.BasicAuth via proxy_auth (cleaner than inlining them in the URL):

Python
import asyncio
import aiohttp

PROXY = "http://gw-2312.coldproxy.com:30000"
AUTH = aiohttp.BasicAuth("USERNAME", "PASSWORD")

async def main():
    async with aiohttp.ClientSession() as session:
        async with session.get(
            "https://api.vipv6proxy.com/api/checker/my-ip",
            proxy=PROXY,
            proxy_auth=AUTH,
        ) as resp:
            print(await resp.json())

asyncio.run(main())
Note

aiohttp's built-in proxy support takes HTTP proxy URLs only. For SOCKS5 use the aiohttp-socks connector below.

SOCKS5 with aiohttp (aiohttp-socks)

Install aiohttp-socks and build a ProxyConnector from a socks5:// URL, then hand it to the session. Pass rdns=True so the hostname resolves at the proxy (remote DNS); with from_url() it is not enabled by default:

Shell
pip install aiohttp-socks
Python
import asyncio
import aiohttp
from aiohttp_socks import ProxyConnector

async def main():
    connector = ProxyConnector.from_url(
        "socks5://USERNAME:[email protected]:30000",
        rdns=True,
    )
    async with aiohttp.ClientSession(connector=connector) as session:
        async with session.get("https://api.vipv6proxy.com/api/checker/my-ip") as resp:
            print(await resp.json())

asyncio.run(main())

Rotating vs. sticky sessions

ColdProxy encodes geo-targeting and session control in the username, so rotation and stickiness change only the credentials; the host and port stay the same. The username grammar is user-key-value-key-value..., with the password passed as the password field; the full reference is the Username tag scheme.

Rotating (a fresh IP per request)

With no session tag you get a new IP per request. Add a geo tag (for example a country) to rotate within that location:

Python
import requests

# Rotating, country-targeted (US): new exit IP on each request
proxy = "http://user-country-us:[email protected]:30000"
proxies = {"http": proxy, "https": proxy}

for _ in range(3):
    r = requests.get("https://api.vipv6proxy.com/api/checker/my-ip", proxies=proxies, timeout=30)
    print(r.json())  # IP changes each call

Sticky (keep the same IP for a session)

A sticky IP needs both a session ID and a duration tag: -session-<id> and -time-<duration>. With only one, the request still rotates:

Python
import requests

# Sticky: same US exit IP for ~10 minutes for session id "481516"
proxy = "http://user-country-us-session-481516-time-10m:[email protected]:30000"
proxies = {"http": proxy, "https": proxy}

for _ in range(3):
    r = requests.get("https://api.vipv6proxy.com/api/checker/my-ip", proxies=proxies, timeout=30)
    print(r.json())  # same IP across calls within the window

The same username tags work identically in the httpx and aiohttp examples above; only the username string changes.

Note

The exact tag prefixes shown here (country, session, time, etc.) are configured per product by ColdProxy. Confirm the precise prefixes for your plan in your client area before scripting them. Sticky duration limits: Residential IPv4 (both) support 5s-24h; Residential IPv6 and Datacenter IPv6 support 5s-FOREVER. See Rotating and sticky proxies explained and geo-targeting with proxies.

IP whitelist (no username/password)

If you authorize your server's IP in the client area (up to 50 IPs), connect with just the host and port: no credentials. With IP authentication the proxies are issued in IP:PORT form and geo defaults to Worldwide unless SuperPorts are configured:

Python
import requests

# IP-authenticated: your server's IP is whitelisted, so no user:pass
proxy = "http://gw-2312.coldproxy.com:30000"
proxies = {"http": proxy, "https": proxy}

resp = requests.get("https://api.vipv6proxy.com/api/checker/my-ip", proxies=proxies, timeout=30)
print(resp.json())
Tip

Username/password and IP authentication can both be active at once. To geo-target IP-auth traffic without username tags, configure SuperPorts to bind country/state/city and session settings to specific port ranges. See IP whitelisting.

Verify the connection

The ColdProxy IP-echo endpoint (https://api.vipv6proxy.com/api/checker/my-ip) confirms the exit IP and that auth works. You can also use the ColdProxy proxy checker and My IP tools to confirm reachability, exit IP, and location. On an IPv6 plan, run the IPv6 checker against your target first; many sites are IPv4-only (no AAAA DNS record) and will not respond over IPv6.

Warning

A 407 Proxy Authentication Required error means the credentials were rejected or omitted; re-check the username tags and password (and URL-encode special characters). A 403/429 from the target site is a site-side block, not a proxy auth failure. See Common errors & fixes and Proxy error codes 407, 403, 429, 502 and 504 explained.

Next steps

Tailored Commercial Plans

Have a Large Project?

When the public plans don’t quite fit, ColdProxy can shape a tailored commercial plan around your workflow — custom speed tiers, custom monthly GB limits, and a plan built from Residential IPv4, Residential IPv6, or Datacenter IPv6.

  • Custom speed & GB quotasCustom speed and monthly GB limits set to match how much traffic you run and which proxy types you use.
  • Across the product lineupResidential IPv4 (Unmetered or GB-based), Residential IPv6, and Datacenter IPv6, sized to fit your project.
  • Built around your workflowPricing, capacity, and session settings (rotating or sticky) matched to your project instead of a fixed package.
Contact Our Sales TeamTelegram & ticket support · English and Arabic