You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using httpx.AsyncClient, it doesn't automatically read proxy settings from environment variables, while httpx.Client does. This leads to inconsistent behavior between sync and async clients.
Reproduction Steps
Here's a minimal example demonstrating the issue:
importhttpximportasyncioimportos# Set proxy environment variablesos.environ["HTTPS_PROXY"] ="socks5://127.0.0.1:13659"os.environ["ALL_PROXY"] ="socks5://127.0.0.1:13659"# Test sync clientdeftest_sync():
withhttpx.Client() asclient:
response=client.get("http://httpbin.org/ip")
print(f"Sync client IP: {response.text}")
# Test async clientasyncdeftest_async():
asyncwithhttpx.AsyncClient() asclient:
response=awaitclient.get("http://httpbin.org/ip")
print(f"Async client IP: {response.text}")
# Run testsprint("Testing sync client:")
test_sync()
print("\nTesting async client:")
asyncio.run(test_async())
Current Behavior
Sync client (httpx.Client) correctly uses the proxy from environment variables
Async client (httpx.AsyncClient) ignores environment variables and makes direct connections
Expected Behavior
Both sync and async clients should respect proxy settings from environment variables consistently.
Workarounds
Currently, we have to explicitly set proxies for AsyncClient to work:
This inconsistency can cause issues in libraries that use httpx's AsyncClient internally, as users might expect environment variables to work the same way as they do with the sync client.
The text was updated successfully, but these errors were encountered:
Issue Description
When using
httpx.AsyncClient
, it doesn't automatically read proxy settings from environment variables, whilehttpx.Client
does. This leads to inconsistent behavior between sync and async clients.Reproduction Steps
Here's a minimal example demonstrating the issue:
Current Behavior
httpx.Client
) correctly uses the proxy from environment variableshttpx.AsyncClient
) ignores environment variables and makes direct connectionsExpected Behavior
Both sync and async clients should respect proxy settings from environment variables consistently.
Workarounds
Currently, we have to explicitly set proxies for AsyncClient to work:
Environment
Additional Context
This inconsistency can cause issues in libraries that use httpx's AsyncClient internally, as users might expect environment variables to work the same way as they do with the sync client.
The text was updated successfully, but these errors were encountered: