Skip to content

Commit 5ba1101

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 7593e79 commit 5ba1101

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

insights/client/connection.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,19 @@ 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):
576-
logger.error(" Invalid key or certificate.")
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):
584+
if "[SSL: WRONG_VERSION_NUMBER]" in str(root_cause):
585+
logger.error(" Invalid proxy address protocol.")
586+
else:
587+
logger.error(" Invalid key or certificate.")
577588
elif isinstance(result, requests.exceptions.ConnectionError) and isinstance(root_cause, socket.gaierror):
578589
self._test_connection(url)
579590
else:

0 commit comments

Comments
 (0)