Environment var HTTP_PROXY is not respected when HTTPTransport is passed as argument #2593
Unanswered
tscheburaschka
asked this question in
Potential Issue
Replies: 1 comment
-
|
I am also affected by this. When using a custom transport, loading proxy configuration from environ is disabled in clients like AsyncClient: allow_env_proxies = trust_env and app is None and transport is None
proxy_map = self._get_proxy_map(proxies or proxy, allow_env_proxies)A dummy example to reproduce this (it assumes the only internet access is via a proxy, passed via import httpx
class CustomTransport(httpx.BaseTransport):
def __init__(self, **kwargs):
self._wrapper = httpx.HTTPTransport(**kwargs)
def handle_request(self, request):
return self._wrapper.handle_request(request)
# OK
with httpx.Client() as c:
print(c.get('https://google.com'))
# NOK
with httpx.Client(transport=CustomTransport()) as c:
print(c.get('https://google.com'))I would love to hear your views on this, is this a design choice? A side effect maybe? Is there any quick fix to bypass this? Should it be addressed in Thanks for reading this and for all the work on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are using httpx as the basic HTTP-client in a library of custom API connectors.
We would like to configure the number of retries and the only way we found was to pass a
httpx.HTTPTransportobject to the instantiation ofhttpx.Client. However, this unexpectedly stopped the client from respecting the environment variable HTTP_PROXY.If this is intended behavior, it would benefit from explicit documentation.
However, I would expect the env vars still to work, even when a transport is passed.
nb: AFAIK, the critical lines are here https://github.com/encode/httpx/blob/master/httpx/_client.py#L669
Beta Was this translation helpful? Give feedback.
All reactions