{"record":{"id":"11675c841b2d515d","repo":"psf/requests","slug":"invalid-url-url-r-no-scheme-supplied-perhaps-y","errorCode":null,"errorMessage":"Invalid URL {url!r}: No scheme supplied. Perhaps you meant https://{url}?","messagePattern":"Invalid URL (.+?): No scheme supplied\\. Perhaps you meant https://(.+?)\\?","errorType":"exception","errorClass":"MissingSchema","httpStatus":null,"severity":"error","filePath":"src/requests/models.py","lineNumber":516,"sourceCode":"\n        # Remove leading whitespaces from url\n        url = url.lstrip()\n\n        # Don't do any URL preparation for non-HTTP schemes like `mailto`,\n        # `data` etc to work around exceptions from `url_parse`, which\n        # handles RFC 3986 only.\n        if \":\" in url and not url.lower().startswith(\"http\"):\n            self.url = url\n            return\n\n        # Support for unicode domain names and paths.\n        try:\n            scheme, auth, host, port, path, query, fragment = parse_url(url)\n        except LocationParseError as e:\n            raise InvalidURL(*e.args)\n\n        if not scheme:\n            raise MissingSchema(\n                f\"Invalid URL {url!r}: No scheme supplied. \"\n                f\"Perhaps you meant https://{url}?\"\n            )\n\n        if not host:\n            raise InvalidURL(f\"Invalid URL {url!r}: No host supplied\")\n\n        # In general, we want to try IDNA encoding the hostname if the string contains\n        # non-ASCII characters. This allows users to automatically get the correct IDNA\n        # behaviour. For strings containing only ASCII characters, we need to also verify\n        # it doesn't start with a wildcard (*), before allowing the unencoded hostname.\n        if not unicode_is_ascii(host):\n            try:\n                host = self._get_idna_encoded_host(host)\n            except UnicodeError:\n                raise InvalidURL(\"URL has an invalid label.\")\n        elif host.startswith((\"*\", \".\")):\n            raise InvalidURL(\"URL has an invalid label.\")","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/models.py#L498-L534","documentation":"Raised by PreparedRequest.prepare_url when parse_url succeeded but returned an empty scheme. Every HTTP(S) request needs a scheme to route through the correct adapter; a URL like 'example.com/path' parses but has no scheme, so requests raises MissingSchema and suggests the most likely fix (prepending 'https://'). This catches the common 'forgot the protocol' mistake.","triggerScenarios":"Calling requests.get('example.com/api') (no scheme); building URLs by concatenating a host without a protocol prefix; receiving a bare hostname from config and passing it straight to requests.","commonSituations":"User-supplied 'domains' instead of full URLs; configs that store hosts separately from schemes; copy-pasting a URL that lost its 'https://' when the browser stripped it.","solutions":["Prefix the URL with a scheme: requests.get('https://' + url) if you know it should be HTTPS, or normalize inputs upstream.","Validate with urllib.parse.urlparse and require a non-empty .scheme before issuing the request.","For 'localhost'-style shortcuts, use the full form 'http://localhost:8000'."],"exampleFix":"// before\nrequests.get('example.com/api')\n\n// after\nrequests.get('https://example.com/api')","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\n\ndef ensure_scheme(url: str, default: str = 'https') -> str:\n    if '://' not in url:\n        url = f'{default}://{url}'\n    return url","typeGuard":"from urllib.parse import urlparse\n\ndef has_scheme(url: str) -> bool:\n    return bool(urlparse(url).scheme)","tryCatchPattern":"from requests.exceptions import MissingSchema\n\ntry:\n    resp = requests.get(url)\nexcept MissingSchema:\n    resp = requests.get('https://' + url)","preventionTips":["Always include the scheme ('https://' or 'http://') when constructing URLs.","Normalize user-supplied domains by prepending a default scheme.","Validate .scheme is non-empty via urlparse before calling requests."],"tags":["url","missingschema","scheme","validation","http"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}