Skip to content

Commit f7dffa9

Browse files
committed
feat: Detect proxy errors
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.
1 parent 7001cef commit f7dffa9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

insights/client/connection.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,15 @@ def test_connection(self, rc=0):
572572

573573
if isinstance(result, REQUEST_FAILED_EXCEPTIONS):
574574
root_cause = _exception_root_cause(result)
575-
if isinstance(result, requests.exceptions.SSLError):
575+
if isinstance(result, requests.exceptions.ProxyError):
576+
proxy_url = self.proxies[urlparse(url).scheme]
577+
if isinstance(root_cause, socket.gaierror):
578+
logger.error(" Could not resolve proxy address %s.", proxy_url)
579+
elif "407 Proxy Authentication Required" in str(root_cause):
580+
logger.error(" Invalid proxy credentials %s.", proxy_url)
581+
else:
582+
logger.error(" Invalid proxy settings %s.", proxy_url)
583+
elif isinstance(result, requests.exceptions.SSLError):
576584
if "[SSL: WRONG_VERSION_NUMBER]" in str(root_cause):
577585
logger.error(" Invalid protocol.")
578586
else:

0 commit comments

Comments
 (0)