Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

SOCKS5 Proxy in Python — requests, httpx & aiohttp

Working SOCKS5 proxy setups for the three Python HTTP clients people actually use, plus the one detail that silently breaks privacy: local vs. remote DNS.

requests

pip install "requests[socks]"
import requests

proxy = "socks5h://USER:PASS@residentialboson.quantumproxies.io:12000"
#             ^ socks5h = DNS resolved by the proxy, not your machine

r = requests.get("https://ipinfo.io/json",
                 proxies={"http": proxy, "https": proxy}, timeout=30)
print(r.json())

socks5:// resolves hostnames locally — your DNS resolver sees every domain you scrape. socks5h:// pushes resolution through the exit node. Use socks5h unless you have a reason not to.

httpx

pip install "httpx[socks]"
import httpx

client = httpx.Client(proxy="socks5://USER:PASS@residentialboson.quantumproxies.io:12000")
print(client.get("https://ipinfo.io/json").json())

aiohttp

pip install aiohttp aiohttp-socks
from aiohttp_socks import ProxyConnector
import aiohttp, asyncio

async def main():
    connector = ProxyConnector.from_url("socks5://USER:PASS@residentialboson.quantumproxies.io:12000")
    async with aiohttp.ClientSession(connector=connector) as s:
        async with s.get("https://ipinfo.io/json") as r:
            print(await r.json())

asyncio.run(main())

When SOCKS5 over HTTP proxies

SOCKS5 is protocol-agnostic — it tunnels raw TCP. That covers non-HTTP traffic (custom protocols, some anti-bot WebSocket checks) and avoids proxy-side header rewriting entirely. Geo flags work the same as HTTP: USER-country-de, -session-x9-lifetime-10, etc.

Full demo across all three clients: socks5.py.

Endpoint used here: QuantumProxies SOCKS5 proxies — residential SOCKS5 on port 12000, 195+ countries, per-GB billing, credentials from app.quantumproxies.io.

About

SOCKS5 proxies in Python with requests, httpx and aiohttp — and why socks5h beats socks5.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages