Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DigestAuth doesn't support connecting to HTTPS websites #321

Open
raffaem opened this issue Dec 31, 2021 · 0 comments
Open

DigestAuth doesn't support connecting to HTTPS websites #321

raffaem opened this issue Dec 31, 2021 · 0 comments

Comments

@raffaem
Copy link

raffaem commented Dec 31, 2021

DigestAuth seems to not work when connecting to a HTTPS website.

For instance, the following code works:

#!/usr/bin/env python3

import requests
from requests_toolbelt.auth.http_proxy_digest import HTTPProxyDigestAuth

proxies = {
    "http": "http://MYPROXY:8080",
    "https": "http://MYPROXY:8080",
}

url = "http://verify.MYPROXY"

auth = HTTPProxyDigestAuth("USERNAME", "PASSWORD")

s = requests.get(url, proxies=proxies, auth=auth)

print(s.status_code)

The returned status_code is 200.

But if you replace url with an HTTPS URL:

url = "https://dev.elsevier.com"

It will raise an exception, reported below.

The following post contains an implementation that works also when connecting to HTTPS websites.

$ ./toolbelt_test.py 
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/urllib3/connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "/usr/lib/python3.10/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "/usr/lib/python3.10/site-packages/urllib3/connection.py", line 366, in connect
    self._tunnel()
  File "/usr/lib64/python3.10/http/client.py", line 924, in _tunnel
    raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
OSError: Tunnel connection failed: 407 Proxy Authentication Required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.10/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.10/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dev.elsevier.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/./toolbelt_test.py", line 16, in <module>
    s = requests.get(url, proxies=proxies, auth=auth)
  File "/usr/lib/python3.10/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='dev.elsevier.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))
@raffaem raffaem changed the title DigestAuth don't support connecting to HTTPS website DigestAuth doesn't support connecting to HTTPS websites Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant