Httpx: trust_env is partially ignored for httpx.get calls

Created on 6 Nov 2019  路  2Comments  路  Source: encode/httpx

I have a socks5 proxy used in the system and it's not supported by httpx. all_proxy environmental variable points to socks5 proxy, therefore httpx.get('https://httpbin.org/get') call results in an error (Unknown proxy for URL).

To bypass that I specify trust_env=False like this httpx.get('https://httpbin.org/get', trust_env=False), but still get the same error.

I looked up the request method implementation in the api.py and apparently when the Client instance is created none of the request method parameters are being passed to the constructor.

https://github.com/encode/httpx/blob/master/httpx/api.py#L80

Therefore inside the BaseClient's __init__ method trust_env has the default value (True). And accordingly to this value tries to deduce the proxy settings from the environment variable, which causes the error.

It would be great if you passed the trust_env value to __init__ when creating Client's instance.

bug good first issue

Most helpful comment

Good catch, yup. I think we should only pass trust_env to the Client in that case, and not bother including it on the request (it will just default to the client value).

Stylistically I'd be tempted to do the same for timeout, cert, verify too, which are more typically per-client than per-request.

All 2 comments

Good catch, yup. I think we should only pass trust_env to the Client in that case, and not bother including it on the request (it will just default to the client value).

Stylistically I'd be tempted to do the same for timeout, cert, verify too, which are more typically per-client than per-request.

Closed via #544

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sethmlarson picture sethmlarson  路  5Comments

njsmith picture njsmith  路  3Comments

paulchubatyy picture paulchubatyy  路  4Comments

kde713 picture kde713  路  3Comments

innawe picture innawe  路  3Comments