Originally published on proxymint.
Set a proxy in Python httpx after 0.28 removed proxies=: proxy= and mounts, auth, SOCKS5, AsyncClient pool limits, rotation and the errors each mistake raises.
TL;DR
- httpx takes one proxy= argument now. httpx.Client(proxy="http://USERNAME:PASSWORD@HOST:PORT") routes HTTP and HTTPS. The old proxies= argument was removed in 0.28.0 and raises a TypeError; per-scheme or per-host routing moved to mounts=.
- The proxy URL stays http:// for HTTPS sites. httpx sends CONNECT through the proxy and TLS runs end to end with the site. An https:// proxy URL means TLS to the proxy itself and usually ends in a handshake timeout.
- An explicit proxy beats the environment. With proxy= set, httpx ignores HTTP_PROXY and HTTPS_PROXY. Passing a custom transport= switches environment proxies off without any error.
- Each concurrent HTTPS request is its own tunnel. An AsyncClient opens up to 100 connections by default, each a separate CONNECT to the proxy port. PoolTimeout means the client's own pool ran out, not that the proxy failed.
- There is no per-request proxy in httpx. Rotation happens behind one gateway URL or across one client per endpoint, and keep-alive can hold one exit on a reused tunnel.
Key takeaways
- Replace proxies= with proxy= or mounts= when upgrading. Wrap per-scheme proxies in httpx.HTTPTransport or httpx.AsyncHTTPTransport inside mounts, and pass limits to each mounted transport.
- Percent-encode credentials or pass them as a tuple. A /, # or ? in a raw password raises InvalidURL; httpx.Proxy(url, auth=(user, password)) avoids encoding altogether.
- Catch httpx.ProxyError for HTTPS targets. A 407 on an HTTPS site is an exception, not a response, so a status_code check never sees it.
- Bound concurrency with a semaphore that matches max_connections. Raise max_keepalive_connections to the same number for steady load and set timeouts above the 5-second default.
- Retry in the job, not with HTTPTransport(retries=). In 0.28.1 the retries value never reaches the proxy pools; retry 429, 5xx and timeouts with backoff, never 407 or 403.
Read the full guide on proxymint, with the commands, tables and sources.
Top comments (0)