Skip to content

When using httpx.Client with proxies, authentication fails #779

Closed

Description

@fbexiga

When doing something like this

proxy = {
     'http' : 'http://user:pass@X.X.X.X:YY',
     'https' : 'http://user:pass@X.X.X.X:YY'
}

def run_sync(url):
    with httpx.Client(verify=False, proxies=proxy) as client:
        response = client.get(url)
        print(response)
>>> run_sync('http://www.google.com')
<Response [407 Proxy Authentication Required]>

For a private proxy that includes authentication, the request will fail with a "Proxy Authentication Required" error. I think httpx is doing something like this:

>>> from urllib3 import ProxyManager
>>> proxy = urllib3.ProxyManager('http://user:pass@x.x.x.x:yy')
>>> x = proxy.request('GET', 'http://google.com/')
>>> x.status
407

instead of this

>>> from urllib3 import ProxyManager, make_headers
>>> default_headers = make_headers(proxy_basic_auth='user:pass')
>>> proxy = urllib3.ProxyManager('http://x.x.x.x:yy', headers=default_headers)
>>> x = proxy.request('GET', 'http://google.com/')
>>> x.status
200
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 working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions