Repository navigation
Problem with proxies parameter in AsyncClient after update to 0.28.0 #3490
Replies: 1 comment
|
import asyncio
import httpx
async def main():
proxy_config = {
"http://": "http://127.0.0.1:8030",
"https://": "http://127.0.0.1:8031",
}
mounts = {
scheme: httpx.AsyncHTTPTransport(proxy=proxy_url)
for scheme, proxy_url in proxy_config.items()
}
async with httpx.AsyncClient(mounts=mounts) as client:
for url in ("http://www.example.com/", "https://www.example.com/"):
response = await client.get(url)
response.raise_for_status()
print(response.status_code)
asyncio.run(main())Replace the loopback addresses with your actual proxy endpoints. The mapping keys describe the destination URL scheme; each value's URL describes the connection to the proxy. An HTTPS destination can therefore use an If both schemes use the same proxy, there is no need for a mapping: async with httpx.AsyncClient(proxy="http://127.0.0.1:8030") as client:
response = await client.get("https://www.example.com/")The proxy documentation shows the mounts approach with synchronous Verified on HTTPX 0.28.1 / Python 3.13.13 with three local checks: the removed-keyword error, separate proxy routing for HTTP and HTTPS (including CONNECT and a TLS-verified response), and one shared proxy for both schemes. Prepared and tested with Codex assistance. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
After updating to version 0.28.1, the
proxiesparameter is no longer accepted inhttpx.AsyncClient, resulting in the following error:TypeError("AsyncClient.init() got an unexpected keyword argument 'proxies'")
Before this update, the
proxiesparameter was correctly used to configure proxies directly in theAsyncClientinstance. However, with the current version, attempting to pass theproxiesparameter to configure proxies results in the error mentioned above.Steps to Reproduce:
httpxin your virtual environment.AsyncClientwith theproxiesparameter configured:How can I configure multiple proxies (both HTTP and HTTPS) in version 0.28.1 of httpx, considering that the proxies parameter is no longer accepted?
All reactions