Proxies for Python: 10 Lines of Code

Falcon Cyber · 12.08.2026

Connecting a proxy in Python is literally a few lines. The requests library does everything: you pass a proxy dict, and requests go through the desired address. Example: requests.get(url, proxies={"http": "socks5h://ip:port", "https": "socks5h://ip:port"}).

For SOCKS5 you need the requests[socks] package — one install command. After that everything works. Do not forget the h in socks5h: it enables DNS resolution through the proxy, otherwise domains resolve on your side.

When you write Python scripts with proxies long-term, take addresses from an API, not from a file. One request — a batch of fresh proxies. That way the script won't die when the list goes stale.

And set timeouts: if a proxy does not answer in 10 seconds — move to the next one. That is the basic survival rule for a scraper.