How to Use a SOCKS5 Proxy with Python, cURL, and Browser Automation
A proxy is only useful when it works reliably in the tool that runs your request. Many proxy tutorials stop after showing a single command and never explain DNS resolution, authentication failures, connection pooling, or browser-specific behavior. This guide takes a practical approach to using SOCKS5 proxies with cURL, Python, and browser automation tools.
The examples use standard SOCKS5 credentials in the form HOST: PORT, with optional username and password authentication. If your application needs a different IP for each session or a specific country, dynamic residential proxies are usually more suitable than a single static server address.
The commands below can be adapted to most SOCKS5 providers. SOCKS5.io supports geographically targeted proxy access, rotating sessions, and both username/password and IP-whitelist authentication through its dashboard. Always confirm the current endpoint, port, authentication rules, and usage limits in your provider account before running production traffic.

What Is a SOCKS5 Proxy?
SOCKS5 is a proxy protocol that operates below the application layer. Instead of understanding HTTP requests itself, it forwards TCP connections on behalf of the client. This makes it useful for web requests, API clients, command-line tools, database connections, and browser automation.
The term “SOCKS5” does not automatically mean encryption. The connection between your application and the Proxy may be authenticated, but the proxy protocol itself is not a replacement for HTTPS, TLS, or end-to-end encryption. Use HTTPS whenever the destination supports it, and never send credentials over an unencrypted connection.
A SOCKS5 proxy can also handle DNS lookups in two different ways:
- socks5:// often resolves the hostname locally before connecting.
- socks5h:// asks the Proxy to resolve the hostname remotely.
The second option is important when you want the destination to see the Proxy’s DNS path rather than your local resolver.
SOCKS5 Proxy Information You Need
Before configuring any client, collect these values:
| Field | Example | Purpose |
| Proxy host | proxy.example.com | DNS name or IP address of the Proxy |
| Port | 3000 | Listening port exposed by the provider |
| Username | your_user | Credential-based authentication |
| Password | your_password | Credential-based authentication |
| Location | United States | Exit geography, if supported |
| Session type | Rotating or sticky | Determines whether the IP changes |
| Protocol | SOCKS5 | Protocol expected by the client |
Do not paste real credentials into source code that is committed to Git. Use environment variables or a secret manager instead.
For a SOCKS5.io endpoint, the exact hostname and port depend on your product and location settings. A typical configuration may look like:
Plaintext
PROXY_HOST=proxy-na.socks5.io
PROXY_PORT=3000
PROXY_USER=USERNAME
PROXY_PASSWORD=PASSWORD
Test the Proxy with cURL
cURL is the fastest way to verify whether the endpoint works before troubleshooting application code.
Basic SOCKS5 request
Bash
curl –proxy socks5h://USERNAME:PASSWORD@proxy-na.socks5.io:3000 \
https://api.ipify.org
The response should be the proxy exit IP, not the public IP assigned to your local network.
The socks5h prefix is deliberate. It sends hostname resolution through the Proxy. If you use socks5:// instead, DNS may be resolved locally depending on the cURL build and operating system.
Verbose connection diagnostics
Bash
curl -v –proxy socks5h://USERNAME:PASSWORD@proxy-na.socks5.io:3000 \
https://example.com/
Look for a successful connection to the proxy host, SOCKS5 negotiation, successful username/password authentication, a response from the destination server, and TLS negotiation with the destination. Remove usernames, passwords, tokens, and internal hostnames before sharing verbose logs.
Using an IP allowlist
Some providers allow authentication by adding your public IP address in a dashboard. In that case, omit the username and password:
Bash
curl –proxy socks5h://proxy-na.socks5.io:3000 \
https://api.ipify.org
IP allowlisting is useful if the servers’ public IP addresses are fixed. If the IP address of a laptop, home connection, or cloud instance changes, it’s less convenient.
Testing a destination
An IP check does not ensure that the target site accepts the request; it only verifies that it’s being routed. Test a location that is suitable for your tasks:
Bash
curl –fail –silent –show-error \
–proxy socks5h://USERNAME:PASSWORD@proxy-na.socks5.io:3000 \
-o /dev/null \
-w “HTTP %{http_code}, total %{time_total}s\n” \
https://example.com/
Configure SOCKS5 in Python
Python’s requests library supports SOCKS proxies through an optional dependency.
Install SOCKS support
Bash
python -m pip install “requests[socks]”
This installs PySocks, the adapter used by Requests.
A minimal Requests example
Python
import os
import requests
proxy_url = (
f”socks5h://{os.environ[‘PROXY_USER’]}:”
f”{os.environ[‘PROXY_PASSWORD’]}@{os.environ[‘PROXY_HOST’]}:”
f”{os.environ[‘PROXY_PORT’]}”
)
proxies = {“http”: proxy_url, “https”: proxy_url}
response = requestsget(
“https://api.ipify.org?format=json”,
proxies=proxies,
timeout=(10, 30),
)
response.raise_for_status()
print(response.json())
The timeout tuple gives the client 10 seconds to connect and 30 seconds to read. Avoid disabling timeouts: a dead proxy can otherwise occupy a worker indefinitely.
Reuse a Session
For multiple requests, use requests.Session() so connections and headers can be managed consistently:
Python
import os
import requests
proxy_url = (
f”socks5h://{os.environ[‘PROXY_USER’]}:”
f”{os.environ[‘PROXY_PASSWORD’]}@{os.environ[‘PROXY_HOST’]}:”
f”{os.environ[‘PROXY_PORT’]}”
)
with requests.Session() as session:
session.proxies.update({“http”: proxy_url, “https”: proxy_url})
session.headers.update({“User-Agent”: “ResearchClient/1.0”})
result = session.get(“https://httpbin.org/ip”, timeout=(10, 30))
result.raise_for_status()
print(result.json())
Use a descriptive User-Agent for legitimate data collection. Do not imitate a browser or conceal automated traffic when the target’s terms prohibit it.
URL-encode special characters
If a username or password contains @,:, /, or another reserved character, encode it before constructing the proxy URL:
Python
from urllibparse import quote
username = quote(os.environ[“PROXY_USER”], safe=””)
password = quote(os.environ[“PROXY_PASSWORD”], safe=””)
Malformed URLs are a common cause of misleading “invalid credentials” errors.
Use SOCKS5 with Playwright
Playwright accepts a proxy configuration when launching a browser:
Bash
python -m pip install playwright
playwright install chromium
Python
import os
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
headless=True,
proxy={
“server”: f”socks5://{os.environ[‘PROXY_HOST’]}:”
f”{os.environ[‘PROXY_PORT’]}”,
“username”: os.environ[“PROXY_USER”],
“password”: os.environ[“PROXY_PASSWORD”],
},
)
page = browser.new_page()
page.goto(“https://api.ipify.org”, wait_until=”domcontentloaded”)
print(page.text_content(“body”))
browser.close()
This option is enabled at launch and is defined as Playwright’s proxy setting. Make multiple browser instances or contexts for different locations or sessions based on the provider’s supported behavior.
Use SOCKS5 with Selenium
The behavior of Selenium’s SOCKS5 is browser- and driver-specific. In Chrome, you can pass a proxy argument to unauthenticated endpoints:
Python
from selenium import webdriver
from selenium. chrome. options import Options
options = Options()
options.add_argument(“–headless=new”)
options.add_argument(“–proxy-server=socks5://proxy.example.com:3000”)
driver = webdriverChrome(options=options)
driver.get(“https://api.ipify.org”)
print(driver.find_element(“tag name”, “body”).text)
driver.quit()
Authenticated SOCKS5 can be an extension or a local authentication bridge. Playwright might be easier to use if you rely on authentication for your work.
Rotating and Sticky Sessions
| Requirement | Better choice |
| Independent public-page requests | Rotating session |
| Login, checkout, or multi-step workflow | Sticky session |
| Long-lived API connection | Static or sticky endpoint |
| Country-specific search testing | Rotation within the selected country |
| Large parallel collection job | Rotating pool with controlled concurrency |
If the IP is changed per request, it could cause the loss of login sessions, shopping carts, or multi-step forms. Don’t use rotation as a standalone approach to sensible concurrency, caching, backoff, and adherence to a target site’s rules.
Troubleshooting Common Errors
Connection refused or timeout: Check host and port, account status, location availability, and firewall rules. Try it out using cURL first.
Authentication failed: Check the whitespace, expired credentials, URL encoding, and whether IP allowlisting is required.
The local IP is proxy-visible: Make sure that the application is using the proxy and that no DNS is being resolved locally. Use socks5h if possible.
Slow responses: Use proxy connection time in addition to destination response time. Please use a different proxy type, lower concurrency, or a closer location.
Browser fails while cURL works: Check browser launch syntax, driver versions, authentication handling, JavaScript requirements, and TLS behavior.
Only some domains fail: The destination may block the exit ASN, require another location, or reject automated traffic. A new proxy is not a guaranteed fix.
How to Evaluate a SOCKS5 Provider
Don’t be fooled by the suggested IP count. Check geographic coverage, city-level targeting, residential/datacenter/mobile/IPv6 options, rotation controls, authentication options, success rate for targeted domains, 95th percentile latency, pricing transparency, usage analytics, support, and abuse policies.
SOCKS5.io provides geographic targeting, rotation sessions, residential and datacenter, mobile connections, and dashboard controls. It promises to reach over 195 countries and has plans and static IPs for residential use. Consider those numbers as provider claims – run a small representative test and validate pricing and availability ahead of scaling.
Responsible and Secure Use
Do not misuse proxies for unethical activities like software testing, localization testing, market research, uptime tracking, or gathering public data, except as otherwise expressly authorized. Abide by terms of service, robots.txt instructions, rate limits, privacy policies, and applicable laws. Keep credentials in a safe place, change credentials if exposed, and log only information necessary to debug the application.
Frequently Asked Questions
Does SOCKS5 encrypt traffic?
SOCKS5 is not an end-to-end encryption method; it merely forwards traffic. If confidentiality is important, use HTTPS, SSH, or other layers of encryption.
Should I use socks5:// or socks5h://?
Use socks5:// when DNS resolution should happen through the proxy. Confirm that your library supports the scheme.
Can I use SOCKS5 with Python Requests?
Yes. Install requests[socks], configure both HTTP and HTTPS proxy entries, and set explicit timeouts.
Is a residential proxy always better than a datacenter proxy?
A residential route may be useful for traffic coming from the target if it’s consumer-network traffic; datacenter routes are generally quicker and more economical for testing infrastructure .Use ProxyWorkload to determine your choice.
Should I rotate the proxy for every browser request?
Usually not. For workflows that require multiple steps, stick to sticky sessions; for independent steps, rotate.
How do I verify a proxy?
Request an IP-echo service via it, and then test a representative target. Monitor DNS activity, status codes, latency, errors, etc.
Why does cURL work while Selenium fails?
You might be using a different proxy syntax or proxy authentication. Test the endpoint separately using cURL, and then test the browser and driver configuration.
Is SOCKS5 suitable for web scraping?
It may be, provided it is legal and polite. Use conservative concurrency, caching, backoff, and only retrieve information that you are allowed to retrieve – particularly using an accurate user agent header.