Skip to content

trust_env is partially ignored for httpx.get calls #505

Closed

Description

@dmitriyshashkin

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.

Activity

  1. lovelydinosaur commented on Nov 6, 2019

    @lovelydinosaur
    Member

    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.

  2. lovelydinosaur commented on Nov 27, 2019

    @lovelydinosaur
    Member

    Closed via #544

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions