Skip to content

Commit

Permalink
feat: Detect proxy errors
Browse files Browse the repository at this point in the history
HTTPS proxy introduces several possible error cases, similar to the actual remote server connection:

* proxy name resolution (DNS) error,
* proxy connection error,
* proxy authentication error.

The proxy authentication error can only be recognized by a string in the underlying OSError: the outer exception is a plain remote server connection error.

Although the proxy is used for HTTPS connection, the actual communication for the proxy itself is HTTP. Thus, specifying a HTTPS protocol for the proxy causes a specific WRONG_VERSION_NUMBER SSL error.
  • Loading branch information
Glutexo committed Jan 3, 2025
1 parent 7593e79 commit 5ba1101
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions insights/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,19 @@ def test_connection(self, rc=0):

if isinstance(result, REQUEST_FAILED_EXCEPTIONS):
root_cause = _exception_root_cause(result)
if isinstance(result, requests.exceptions.SSLError):
logger.error(" Invalid key or certificate.")
if isinstance(result, requests.exceptions.ProxyError):
proxy_url = self.proxies[urlparse(url).scheme]
if isinstance(root_cause, socket.gaierror):
logger.error(" Could not resolve proxy address %s.", proxy_url)
elif "407 Proxy Authentication Required" in str(root_cause):
logger.error(" Invalid proxy credentials %s.", proxy_url)
else:
logger.error(" Invalid proxy settings %s.", proxy_url)
elif isinstance(result, requests.exceptions.SSLError):
if "[SSL: WRONG_VERSION_NUMBER]" in str(root_cause):
logger.error(" Invalid proxy address protocol.")
else:
logger.error(" Invalid key or certificate.")
elif isinstance(result, requests.exceptions.ConnectionError) and isinstance(root_cause, socket.gaierror):
self._test_connection(url)
else:
Expand Down

0 comments on commit 5ba1101

Please sign in to comment.