Modern Python HTTP client with sync and async support. HTTPX works as a drop-in replacement for requests with built-in HTTP/2 and async capabilities.
Install from PyPI.
pip install httpxPass proxy URL to the client.
import httpx
client = httpx.Client(proxy="http://USER:PASS@gw.knoxproxy.com:7000")
response = client.get("https://httpbin.org/ip")
print(response.json())Use AsyncClient for concurrent requests.
async with httpx.AsyncClient(proxy="http://USER:PASS@gw.knoxproxy.com:7000") as client:
response = await client.get("https://httpbin.org/ip")
print(response.json())Add country to username.
proxy = "http://USER-country-gb:PASS@gw.knoxproxy.com:7000"Append session ID to username.
proxy = "http://USER-session-s1:PASS@gw.knoxproxy.com:7000"Verify exit IP.
print(client.get("https://httpbin.org/ip").json())"""KnoxProxy + HTTPX -- sync and async examples."""
import httpx
PROXY = "http://USER:PASS@gw.knoxproxy.com:7000"
# Synchronous
with httpx.Client(proxy=PROXY, timeout=30) as client:
r = client.get("https://httpbin.org/ip")
print(f"Sync IP: {r.json()['origin']}")
# Asynchronous
import asyncio
async def main():
async with httpx.AsyncClient(proxy=PROXY, timeout=30) as client:
r = await client.get("https://httpbin.org/ip")
print(f"Async IP: {r.json()['origin']}")
asyncio.run(main())Same as other Python clients. New IP per connection by default; -session-{id} for sticky.
| Problem | Fix |
|---|---|
| ProxyError | Verify URL format and port 7000 is open. |
| ReadTimeout | Increase timeout parameter. |
USER-country-de-city-berlin-session-profile07Order matters -- geo flags before the session flag. The session name is free text; use the profile ID so the mapping is self-documenting. Password stays as issued; no flags belong there. HTTP on :7000, SOCKS5 on :7001, same credentials.
httpx is newer and supports async natively. Use httpx for new projects; requests works fine for existing codebases.
httpx supports HTTP/2, but the proxy gateway uses HTTP/1.1 for the tunnel. The connection to the target site can still negotiate HTTP/2 through the tunnel.
Yes, create a Client or AsyncClient with the proxy parameter and reuse it across requests.
Use httpx.Client(transport=httpx.HTTPTransport(retries=3)) for automatic retries on connection errors.
Free trial on rotating residential -- 3 minutes setup, no credit card.