Tutorials · 5 min read

How to Set Up SOCKS5 Proxies in Python (Requests, HTTPX, Scrapy)

A copy-paste guide to configuring SOCKS5 proxies in the three most popular Python HTTP libraries.

Author

Editorial Team

Published

July 17, 2026

Reading time

5 minutes

UpdatedThis article was reviewed and refreshed on July 17, 2026.
How to Set Up SOCKS5 Proxies in Python (Requests, HTTPX, Scrapy)

Requests

pip install "requests[socks]"
import requests
proxies = {
    "http":  "socks5h://user:pass@gate.example.com:7777",
    "https": "socks5h://user:pass@gate.example.com:7777",
}
r = requests.get("https://httpbin.org/ip", proxies=proxies, timeout=30)
print(r.json())

Always use socks5h — the h routes DNS through the proxy.

HTTPX

pip install "httpx[socks]"
import httpx
client = httpx.Client(proxy="socks5://user:pass@gate.example.com:7777")
r = client.get("https://httpbin.org/ip")
print(r.json())

Scrapy

Install the middleware:

pip install scrapy-proxies

Add to your settings.py:

DOWNLOADER_MIDDLEWARES = {
    'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110,
}

Set http_proxy and https_proxy environment variables to your socks5h:// URL before running scrapy crawl.

Testing

Every provider gives you a test endpoint. Hit it before running anything else — 90% of "my scraper is broken" tickets are credential typos.

Related SOCKS5 deals & promo codes

All deals →

Tags

#python#socks5#tutorial

About the author

Editorial Team

The Best SOCKS5 editorial team independently benchmarks, tests, and audits every SOCKS5 proxy provider we cover. We accept affiliate commissions but never accept paid rankings.