| 1050 | |
| 1051 | |
| 1052 | def _wrap_proxy_error(err: Exception, proxy_scheme: str | None) -> ProxyError: |
| 1053 | # Look for the phrase 'wrong version number', if found |
| 1054 | # then we should warn the user that we're very sure that |
| 1055 | # this proxy is HTTP-only and they have a configuration issue. |
| 1056 | error_normalized = " ".join(re.split("[^a-z]", str(err).lower())) |
| 1057 | is_likely_http_proxy = ( |
| 1058 | "wrong version number" in error_normalized |
| 1059 | or "unknown protocol" in error_normalized |
| 1060 | or "record layer failure" in error_normalized |
| 1061 | ) |
| 1062 | http_proxy_warning = ( |
| 1063 | ". Your proxy appears to only use HTTP and not HTTPS, " |
| 1064 | "try changing your proxy URL to be HTTP. See: " |
| 1065 | "https://urllib3.readthedocs.io/en/latest/advanced-usage.html" |
| 1066 | "#https-proxy-error-http-proxy" |
| 1067 | ) |
| 1068 | new_err = ProxyError( |
| 1069 | f"Unable to connect to proxy" |
| 1070 | f"{http_proxy_warning if is_likely_http_proxy and proxy_scheme == 'https' else ''}", |
| 1071 | err, |
| 1072 | ) |
| 1073 | new_err.__cause__ = err |
| 1074 | return new_err |
| 1075 | |
| 1076 | |
| 1077 | def _get_default_user_agent() -> str: |