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 8, 2025
1 parent 7001cef commit f7dffa9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion insights/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,15 @@ def test_connection(self, rc=0):

if isinstance(result, REQUEST_FAILED_EXCEPTIONS):
root_cause = _exception_root_cause(result)
if isinstance(result, requests.exceptions.SSLError):
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 protocol.")
else:
Expand Down

0 comments on commit f7dffa9

Please sign in to comment.