{"record":{"id":"8b7d06f4fad34a22","repo":"psf/requests","slug":"no-connection-adapters-were-found-for-url-r","errorCode":null,"errorMessage":"No connection adapters were found for {url!r}","messagePattern":"No connection adapters were found for (.+?)","errorType":"exception","errorClass":"InvalidSchema","httpStatus":null,"severity":"error","filePath":"src/requests/sessions.py","lineNumber":881,"sourceCode":"        proxies = merge_setting(proxies, self.proxies)\n        stream = merge_setting(stream, self.stream)\n        verify = merge_setting(verify, self.verify)\n        cert = merge_setting(cert, self.cert)\n\n        return {\"proxies\": proxies, \"stream\": stream, \"verify\": verify, \"cert\": cert}\n\n    def get_adapter(self, url: str) -> BaseAdapter:\n        \"\"\"\n        Returns the appropriate connection adapter for the given URL.\n\n        :rtype: requests.adapters.BaseAdapter\n        \"\"\"\n        for prefix, adapter in self.adapters.items():\n            if url.lower().startswith(prefix.lower()):\n                return adapter\n\n        # Nothing matches :-/\n        raise InvalidSchema(f\"No connection adapters were found for {url!r}\")\n\n    def close(self) -> None:\n        \"\"\"Closes all adapters and as such the session\"\"\"\n        for v in self.adapters.values():\n            v.close()\n\n    def mount(self, prefix: str, adapter: BaseAdapter) -> None:\n        \"\"\"Registers a connection adapter to a prefix.\n\n        Adapters are sorted in descending order by prefix length.\n        \"\"\"\n        self.adapters[prefix] = adapter\n        keys_to_move = [k for k in self.adapters if len(k) < len(prefix)]\n\n        for key in keys_to_move:\n            self.adapters[key] = self.adapters.pop(key)\n\n    def __getstate__(self) -> dict[str, Any]:","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/sessions.py#L863-L899","documentation":"Raised by Session.get_adapter() when no registered adapter prefix matches the URL scheme. Requests ships with adapters for 'http://' and 'https://' only. Any other scheme (or a malformed URL missing the scheme) triggers this InvalidSchema error.","triggerScenarios":"Requesting a URL with scheme 'ftp://', 'file://', 'ws://', or a custom protocol; passing a URL without a scheme like 'example.com/path' (no http:// prefix); passing a URL with a typo like 'htp://'.","commonSituations":"User input missing the 'https://' prefix; configuration files storing URLs without schemes; attempting to access non-HTTP protocols; typos in URL strings; passing relative paths instead of absolute URLs.","solutions":["Ensure the URL starts with 'http://' or 'https://'.","Mount a custom adapter if you need a non-standard scheme: session.mount('ftp://', MyAdapter()).","Validate/sanitize URLs before passing to requests: prepend 'https://' if no scheme is present."],"exampleFix":"# before\nrequests.get('example.com/api')  # InvalidSchema\n\n# after\nrequests.get('https://example.com/api')\n\n# or sanitize\nfrom urllib.parse import urlparse\nif not urlparse(url).scheme:\n    url = 'https://' + url","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\nparsed = urlparse(url)\nif parsed.scheme not in ('http', 'https'):\n    if not parsed.scheme:\n        url = 'https://' + url\n    else:\n        raise ValueError(f'Unsupported scheme: {parsed.scheme}')\nresp = requests.get(url)","typeGuard":"from urllib.parse import urlparse\ndef has_valid_http_scheme(url: str) -> bool:\n    return urlparse(url).scheme in ('http', 'https')","tryCatchPattern":"try:\n    resp = requests.get(url)\nexcept requests.exceptions.InvalidSchema as e:\n    # Prepend scheme and retry\n    url = 'https://' + url\n    resp = requests.get(url)","preventionTips":["Always include the scheme (http:// or https://) in URLs.","Validate URLs from user input before passing to requests.","Mount custom adapters if you need non-HTTP protocols.","Sanitize config file URLs to ensure they include schemes."],"tags":["invalid-schema","url","adapter","session","input-validation"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}