{"id":"d4508c47a13d4149","repo":"encode/httpx","slug":"unknown-scheme-for-proxy-url-url-r","errorCode":null,"errorMessage":"Unknown scheme for proxy URL {url!r}","messagePattern":"Unknown scheme for proxy URL (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"httpx/_config.py","lineNumber":214,"sourceCode":"            f\"max_keepalive_connections={self.max_keepalive_connections}, \"\n            f\"keepalive_expiry={self.keepalive_expiry})\"\n        )\n\n\nclass Proxy:\n    def __init__(\n        self,\n        url: URL | str,\n        *,\n        ssl_context: ssl.SSLContext | None = None,\n        auth: tuple[str, str] | None = None,\n        headers: HeaderTypes | None = None,\n    ) -> None:\n        url = URL(url)\n        headers = Headers(headers)\n\n        if url.scheme not in (\"http\", \"https\", \"socks5\", \"socks5h\"):\n            raise ValueError(f\"Unknown scheme for proxy URL {url!r}\")\n\n        if url.username or url.password:\n            # Remove any auth credentials from the URL.\n            auth = (url.username, url.password)\n            url = url.copy_with(username=None, password=None)\n\n        self.url = url\n        self.auth = auth\n        self.headers = headers\n        self.ssl_context = ssl_context\n\n    @property\n    def raw_auth(self) -> tuple[bytes, bytes] | None:\n        # The proxy authentication as raw bytes.\n        return (\n            None\n            if self.auth is None\n            else (self.auth[0].encode(\"utf-8\"), self.auth[1].encode(\"utf-8\"))","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_config.py#L196-L232","documentation":"Raised as ValueError by Proxy.__init__ when url.scheme is not one of http, https, socks5, socks5h. httpx only supports these proxy schemes; anything else (or a URL missing a scheme) is rejected at construction.","triggerScenarios":"Constructing httpx.Proxy('socks4://host:1080'), httpx.Proxy('ftp://host'), or httpx.Proxy('host:8080') (no scheme).","commonSituations":"Pointing at a SOCKS4 proxy (unsupported); an FTP/other proxy; a bare host:port string with no scheme; typo in the proxy URL.","solutions":["Use a supported scheme: http://, https://, socks5://, or socks5h://.","For SOCKS4 proxies, switch the proxy server to SOCKS5 or use socks5h://.","Ensure the URL has an explicit scheme (add 'http://' if it is an HTTP proxy)."],"exampleFix":"// before\nhttpx.Proxy(\"socks4://host:1080\")  # ValueError\n// after\nhttpx.Proxy(\"socks5://host:1080\")","handlingStrategy":"validation","validationCode":"import httpx\nSUPPORTED = {\"http\", \"https\", \"socks5\", \"socks5h\"}\nparsed = httpx.URL(proxy_url)\nif parsed.scheme not in SUPPORTED:\n    raise ValueError(f\"unsupported proxy scheme {parsed.scheme!r}; use one of {sorted(SUPPORTED)}\")\nproxy = httpx.Proxy(proxy_url)","typeGuard":"import httpx\n\ndef proxy_scheme_supported(url: str) -> bool:\n    return httpx.URL(url).scheme in {\"http\", \"https\", \"socks5\", \"socks5h\"}","tryCatchPattern":"try:\n    proxy = httpx.Proxy(proxy_url)\nexcept ValueError as exc:\n    raise ValueError(f\"Bad proxy URL {proxy_url!r}: {exc}\") from exc","preventionTips":["Restrict proxy URLs to http/https/socks5/socks5h schemes.","Always include an explicit scheme in proxy URLs.","Validate proxy config loaded from environment or settings files."],"tags":["proxy","config"],"analyzedSha":"b5addb64f0161ff6bfe94c124ef76f6a1fba5254","analyzedAt":"2026-08-04T19:32:56.768Z","schemaVersion":2}