Skip to content

Configure TrueProxies with Python

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.

Install the common client libraries:

Terminal window
pip install requests "requests[socks]" aiohttp aiohttp-socks

You 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.

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)
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())
import asyncio
from aiohttp import ClientSession
from 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())
  • 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.