Configure TrueProxies with Python
Overview
Section titled “Overview”TrueProxies works with standard Python HTTP clients over HTTP CONNECT and SOCKS5. You can authenticate with your proxy username and password or with IP allowlisting when enabled for your account.
Installation
Section titled “Installation”Install the common client libraries:
pip install requests "requests[socks]" aiohttp aiohttp-socksYou will need:
- proxy host:
YOUR_HOST - HTTP port:
8080 - SOCKS5 port:
1080 - proxy username
- proxy password
For Residential IPv4 country targeting or sticky sessions, append the documented parameters to the proxy username before using it in code. Do not reuse those parameters for Residential IPv6 or Datacenter IPv6.
HTTP Proxy
Section titled “HTTP Proxy”import requests
username = "your_username"password = "your_password"proxy_url = f"http://{username}:{password}@YOUR_HOST:YOUR_HTTP_PORT"
response = requests.get( "https://httpbin.org/ip", proxies={ "http": proxy_url, "https": proxy_url, }, timeout=30,)
print(response.status_code)print(response.text)SOCKS5 Proxy
Section titled “SOCKS5 Proxy”import requests
username = "your_username"password = "your_password"proxy_url = f"socks5h://{username}:{password}@YOUR_HOST:YOUR_SOCKS_PORT"
response = requests.get( "https://httpbin.org/ip", proxies={ "http": proxy_url, "https": proxy_url, }, timeout=30,)
print(response.json())Async with aiohttp
Section titled “Async with aiohttp”import asyncio
from aiohttp import ClientSessionfrom aiohttp_socks import ProxyConnector
username = "your_username"password = "your_password"connector = ProxyConnector.from_url( f"http://{username}:{password}@YOUR_HOST:YOUR_HTTP_PORT")
async def main() -> None: async with ClientSession(connector=connector) as session: async with session.get("https://httpbin.org/ip", timeout=30) as response: print(response.status) print(await response.text())
asyncio.run(main())Error Handling
Section titled “Error Handling”- Set explicit request timeouts so failed proxy handshakes do not hang workers.
- If you receive authentication failures, re-check your proxy username, password, and any required IP allowlisting.
- If you use Residential IPv4 username parameters for targeting or sticky sessions, log the final username string you send so you can reproduce failures.
- For payment or account-state issues, check the dashboard for billing alerts or suspended-account notices before assuming the proxy endpoint is unhealthy.