Tutorials 2026-03-20

How to Use a SOCKS5 Proxy with Python (2026 Guide)

Step-by-step guide to using SOCKS5 proxies in Python with requests, aiohttp, and urllib3. Includes code examples for web scraping, API calls, and rotating proxies.

How to Use a SOCKS5 Proxy with Python (2026 Guide)

SOCKS5 proxies are the most versatile proxy type — they handle any TCP traffic, support UDP, and don't modify your requests like HTTP proxies do. This guide covers every way to use SOCKS5 proxies in Python.

Proxy setup cheat sheet — quick reference for Python, curl, and browsers

Prerequisites

Install the SOCKS support package:

pip install requests[socks]
# or for async
pip install aiohttp aiohttp-socks

Method 1: Using requests

The simplest approach. The requests library supports SOCKS5 out of the box once you install PySocks.

import requests

proxies = {
    "http": "socks5://127.0.0.1:1080",
    "https": "socks5://127.0.0.1:1080",
}

response = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=10)
print(response.json())
# {"origin": "45.77.xx.xx"}  — the proxy's IP, not yours

With authentication

proxies = {
    "http": "socks5://username:password@127.0.0.1:1080",
    "https": "socks5://username:password@127.0.0.1:1080",
}

SOCKS5 vs SOCKS5h

DNS leak explained — why socks5h prevents DNS leaks

Use socks5h:// to resolve DNS through the proxy (recommended for privacy):

proxies = {
    "http": "socks5h://127.0.0.1:1080",   # DNS resolved by proxy
    "https": "socks5h://127.0.0.1:1080",
}

With plain socks5://, your local machine resolves DNS first — which leaks which domains you're visiting.

Method 2: Using aiohttp (async)

For high-concurrency scraping, async is essential. aiohttp-socks adds SOCKS5 support to aiohttp.

import asyncio
import aiohttp
from aiohttp_socks import ProxyConnector

async def fetch(url):
    connector = ProxyConnector.from_url("socks5://127.0.0.1:1080")
    async with aiohttp.ClientSession(connector=connector) as session:
        async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as resp:
            return await resp.json()

result = asyncio.run(fetch("https://httpbin.org/ip"))
print(result)

Rotating through multiple SOCKS5 proxies

import asyncio
import aiohttp
from aiohttp_socks import ProxyConnector
import random

PROXIES = [
    "socks5://45.77.10.1:1080",
    "socks5://103.21.44.2:1080",
    "socks5://198.44.55.3:1080",
]

async def fetch_with_rotation(url):
    proxy = random.choice(PROXIES)
    connector = ProxyConnector.from_url(proxy)
    async with aiohttp.ClientSession(connector=connector) as session:
        async with session.get(url) as resp:
            return await resp.text()

async def main():
    urls = ["https://httpbin.org/ip"] * 10
    tasks = [fetch_with_rotation(u) for u in urls]
    results = await asyncio.gather(*tasks, return_exceptions=True)
    for r in results:
        print(r)

asyncio.run(main())

Method 3: Using urllib3

Lower-level control with connection pooling:

from urllib3.contrib.socks import SOCKSProxyManager

proxy = SOCKSProxyManager("socks5://127.0.0.1:1080")
response = proxy.request("GET", "https://httpbin.org/ip")
print(response.data.decode())

Loading Proxies from a File

Download the SOCKS5 list from IPProxy.site and load it in Python:

def load_proxies(filepath="socks5_proxies.txt"):
    with open(filepath) as f:
        return [f"socks5://{line.strip()}" for line in f if line.strip()]

proxies = load_proxies()
print(f"Loaded {len(proxies)} SOCKS5 proxies")

Error Handling

Free proxies go down frequently. Always handle failures:

import requests
from requests.exceptions import ProxyError, ConnectTimeout

def fetch_safe(url, proxy_url, timeout=10):
    try:
        resp = requests.get(
            url,
            proxies={"http": proxy_url, "https": proxy_url},
            timeout=timeout,
        )
        return resp.text
    except (ProxyError, ConnectTimeout, ConnectionError):
        return None

When to Use SOCKS5 vs HTTP Proxies

Feature SOCKS5 HTTP
Protocols Any TCP/UDP HTTP/HTTPS only
Speed Faster (no header rewriting) Slower
DNS leaks Can resolve via proxy Always local DNS
Detection Harder to detect Easier to detect
Use case Scraping, apps, games Basic browsing

Where to Get Free SOCKS5 Proxies

IPProxy.site provides a free, validated SOCKS5 proxy list updated every 30 minutes. All proxies are tested for speed and uptime before being listed.

Summary


Get a Fresh, Tested Proxy Right Now

Every proxy is validated every 30 minutes. 1878 working proxies available right now.

← Back to all guides