v1.10.82-f67ee7d
Skip to main content
← Back to Hex Proxies

Python Requests Proxy Integration

Configure Hex Proxies in Python Requests for quick proxy-enabled requests.

Python Requests Proxy Setup

Python Requests is the most popular HTTP library in the Python ecosystem, known for its simple API and human-friendly design. It supports proxy configuration natively, making it the fastest way to start using Hex Proxies in a Python script for web scraping, API testing, or data collection.

Basic Configuration with Credentials

proxies = { 'http': 'http://user:pass@gate.hexproxies.com:8080', 'https': 'http://user:pass@gate.hexproxies.com:8080', }

response = requests.get('https://httpbin.org/ip', proxies=proxies, timeout=30) print(response.json()) ```

Using a Session for Multiple Requests

For better performance across multiple requests, use a Session object which reuses the underlying TCP connection:

session = requests.Session()
session.proxies = {
    'http': 'http://user:pass@gate.hexproxies.com:8080',
    'https': 'http://user:pass@gate.hexproxies.com:8080',

# All requests through this session use the proxy r1 = session.get('https://example.com/page1', timeout=30) r2 = session.get('https://example.com/page2', timeout=30) ```

IP Whitelist Authentication

Whitelist your server IP in the Hex Proxies dashboard, then use the proxy without credentials:

proxies = {
    'http': 'http://gate.hexproxies.com:8080',
    'https': 'http://gate.hexproxies.com:8080',
}

SOCKS5 Proxy Support

Install the SOCKS extra and use a SOCKS5 URL:

pip install requests[socks]
proxies = {
    'http': 'socks5h://user:pass@gate.hexproxies.com:1080',
    'https': 'socks5h://user:pass@gate.hexproxies.com:1080',
}

Use `socks5h` (with the `h` suffix) to resolve DNS remotely through the proxy, preventing DNS leaks.

Best Practices

  • **Always set timeouts** to avoid hanging requests: `timeout=30` is a reasonable default.
  • **Rotate user agents** alongside proxy rotation for stronger fingerprint diversity.
  • Handle exceptions gracefully — catch `requests.exceptions.ProxyError` and `requests.exceptions.Timeout` separately.
  • **Use retries** with the `urllib3.util.Retry` adapter for automatic retry on transient failures.

Troubleshooting

  • **ProxyError: Cannot connect**: Verify the proxy host, port, and credentials. Ensure your firewall allows outbound connections on port 8080.
  • **407 responses**: Authentication failed. Check username/password or verify your IP is whitelisted.
  • **SSLError**: Ensure your Python environment has up-to-date certificates. Try `pip install certifi`.
  • **Slow responses**: Residential proxies add 1-3 seconds of latency. This is normal. Increase timeout values accordingly.

Integration Steps

1

Create proxy config

Set HTTP and HTTPS proxy URLs with credentials.

2

Make requests

Pass proxies to requests.get or a session.

3

Add retries

Handle transient failures with retries and backoff.

Operational Tips

Keep sessions stable for workflows that depend on consistent identity. For high-volume collection, rotate IPs and reduce concurrency if you see timeouts or 403 responses.

  • Prefer sticky sessions for multi-step flows (auth, checkout, forms).
  • Rotate per request for scale and broad coverage.
  • Use timeouts and retries to handle transient failures.

Frequently Asked Questions

Can I use SOCKS5 with Requests?

Yes, with the requests[socks] extra and a socks5 proxy URL.

Ready to Integrate?

Start using residential proxies with Python Requests today.