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.
For new projects, choose httpx over requests with KnoxProxy: httpx supports async natively through AsyncClient, works as a sync drop-in replacement for requests, and adds HTTP/2 support the target site can negotiate through the tunnel. Existing codebases built on requests still work fine and do not need to migrate just for proxy support.
httpx supports HTTP/2 for the connection to the target site, but the KnoxProxy gateway itself always speaks HTTP/1.1 for the CONNECT tunnel between your client and the proxy. Once that tunnel is established, httpx can still negotiate HTTP/2 with the destination server through it, so you get HTTP/2 benefits on the actual page fetch.
Yes, create one httpx.Client or httpx.AsyncClient with the proxy parameter set to your KnoxProxy URL, then reuse that same client instance for every request in your script. Each connection through it gets a new IP by default, or add -session-{id} to the username if you need every request to share one sticky IP.
Configure automatic retries by passing transport=httpx.HTTPTransport(retries=3) when you create the Client, which resends the request up to three times on connection errors without any extra code. This covers transient issues like a slow KnoxProxy gateway response, but for a ReadTimeout on a slow target, increase the timeout parameter on the client instead of relying on retries alone.
Rotating residential proxies -- 3 minutes setup, instant activation, 14-day money-back guarantee.