{"id":"46886a8b6373dd64","repo":"pypa/pip","slug":"please-check-proxy-url-it-is-malformed-and-could","errorCode":null,"errorMessage":"Please check proxy URL. It is malformed and could be missing the host.","messagePattern":"Please check proxy URL\\. It is malformed and could be missing the host\\.","errorType":"exception","errorClass":"InvalidProxyURL","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/requests/adapters.py","lineNumber":496,"sourceCode":"        :rtype:\n            urllib3.HTTPConnectionPool\n        \"\"\"\n        assert _is_prepared(request)\n\n        proxy = select_proxy(request.url, proxies)\n        try:\n            host_params, pool_kwargs = self.build_connection_pool_key_attributes(\n                request,\n                verify,\n                cert,\n            )\n        except ValueError as e:\n            raise InvalidURL(e, request=request)\n        if proxy:\n            proxy = prepend_scheme_if_needed(proxy, \"http\")\n            proxy_url = parse_url(proxy)\n            if not proxy_url.host:\n                raise InvalidProxyURL(\n                    \"Please check proxy URL. It is malformed \"\n                    \"and could be missing the host.\"\n                )\n            proxy_manager = self.proxy_manager_for(proxy)\n            conn = proxy_manager.connection_from_host(\n                **host_params, pool_kwargs=pool_kwargs\n            )\n        else:\n            # Only scheme should be lower case\n            conn = self.poolmanager.connection_from_host(\n                **host_params, pool_kwargs=pool_kwargs\n            )\n\n        return conn\n\n    def get_connection(\n        self, url: str, proxies: dict[str, str] | None = None\n    ) -> HTTPConnectionPool:","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/requests/adapters.py#L478-L514","documentation":"In the modern get_connection_with_tls_context path, after a proxy is selected and given an 'http' scheme prefix, Requests parses it with urllib3 parse_url and raises InvalidProxyURL if the resulting URL has no host component. This means the proxy string is structurally malformed (missing host), not merely unreachable.","triggerScenarios":"Passing a proxies dict whose value parses to a hostless URL, e.g. 'http://', 'http://:8080', or '//' ; calling requests with proxies={'http':'http://'} ; or a SELECTED_PROXY env var that resolves to an empty host. Reached via send() on Requests >= 2.32.2.","commonSituations":"Empty or malformed HTTP_PROXY/HTTPS_PROXY env vars; proxy strings built by concatenation that dropped the host; config templating that produced 'http://:port'; uppercase proxy env vars with stray characters.","solutions":["Correct the proxy URL to include a host, e.g. 'http://proxy.example.com:8080'.","Unset the malformed HTTP_PROXY/HTTPS_PROXY/ALL_PROXY env var if no proxy is intended.","Validate the proxy string with urllib3.util.parse_url and confirm .host is set before passing it to requests."],"exampleFix":"# before\nproxies = {'http': 'http://:8080'}\nrequests.get(url, proxies=proxies)\n\n# after\nproxies = {'http': 'http://proxy.internal:8080'}\nrequests.get(url, proxies=proxies)","handlingStrategy":"validation","validationCode":"from pip._vendor.urllib3.util import parse_url\npu = parse_url(prepend_scheme_if_needed(proxy, 'http'))\nif not pu.host:\n    raise ValueError(f'proxy URL is missing a host: {proxy!r}')","typeGuard":null,"tryCatchPattern":"from pip._vendor.requests.exceptions import InvalidProxyURL\ntry:\n    resp = session.get(url, proxies=proxies)\nexcept InvalidProxyURL:\n    proxies = clean_proxy_config(proxies)\n    resp = session.get(url, proxies=proxies)","preventionTips":["Validate proxy URLs with parse_url and confirm .host before passing to requests.","Sanitize proxy env vars at app startup; unset empty/malformed ones."],"tags":["requests","proxy","config","network"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}