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

MacOS cannot use a proxy with HTTP basic authentication to access HTTPS #6031

Closed
ETOCheney opened this issue Jan 6, 2022 · 3 comments
Closed

Comments

@ETOCheney
Copy link

ETOCheney commented Jan 6, 2022

Expected Result

Displays the proxy IP address

Actual Result

Traceback (most recent call last):
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/urllib3/connection.py", line 371, in connect
self._tunnel()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/http/client.py", line 902, in _tunnel
raise OSError("Tunnel connection failed: %d %s" % (code,
OSError: Tunnel connection failed: 407 Proxy Authentication Required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ifconfig.me', 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 "/Users/cheney/code/python/tools/test.py", line 17, in
res = requests.get("https://ifconfig.me", proxies=proxies)
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/Users/cheney/code/python/tools/venv/lib/python3.8/site-packages/requests/adapters.py", line 513, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='ifconfig.me', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))

Reproduction Steps

When using a proxy that requires basic authentication to access an HTTPS (not HTTP) address, the system gives an error. The code is as follows:

import requests

proxy_string = 'http://{}:{}@{}:{}'.format(username, password, proxyHost, proxyPort)
proxies = {"http": proxy_string, "https": proxy_string}
res = requests.get("https://ifconfig.me", proxies=proxies)
print(res.text)

It should be noted that the same code can run normally in Windows system, but there are problems with MacOS

System Information

$ python -m requests.help
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "2.0.10"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.3"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.8.2"
  },
  "platform": {
    "release": "21.1.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.27.0"
  },
  "system_ssl": {
    "version": "20000000"
  },
  "urllib3": {
    "version": "1.26.7"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}
@ETOCheney ETOCheney changed the title MacOS cannot use a proxy with basic authentication to access HTTPS MacOS cannot use a proxy with HTTP basic authentication to access HTTPS Jan 6, 2022
@sigmavirus24
Copy link
Contributor

Please try 2.27.1, this should have been fixed in that release

@nateprewitt
Copy link
Member

Hi @ETOCheney, this is almost certainly a duplicate of #6027. This should be fixed in the latest release (2.27.1). I'm going to resolve this ticket for now, but please feel free to reopen if you find your issue persists after upgrading. Thanks!

@ETOCheney
Copy link
Author

Hi @ETOCheney, this is almost certainly a duplicate of #6027. This should be fixed in the latest release (2.27.1). I'm going to resolve this ticket for now, but please feel free to reopen if you find your issue persists after upgrading. Thanks!

I tried to upgrade to latest release(2.27.1) and found that the problem has been fixed. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants