{"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/414f0513c33883adf6f2b46901d4f0b38a455851/src/requests/models.py#L498-L534","documentation":"A `MissingSchema` exception raised by `PreparedRequest.prepare_url` when `urllib3.util.parse_url` finds no scheme component in the URL. Requests needs the scheme to pick a connection adapter (http:// vs https://), so a bare host like 'example.com/path' cannot be dispatched. The message suggests the likely fix of prepending https://.","triggerScenarios":"`requests.get('example.com')`, `requests.get('//example.com/x')`, or a URL built by joining strings where the scheme part ended up empty. Note URLs containing ':' that don't start with 'http' (e.g. mailto:) bypass this check entirely at src/requests/models.py:505.","commonSituations":"URLs read from config files, environment variables, CSVs, or user input where people naturally omit the scheme; base-URL concatenation bugs (`base + path` where base is empty or lost its prefix); copy-pasting a domain from a browser bar that hides the scheme.","solutions":["Prepend an explicit scheme: `requests.get('https://' + url)` (as the error message suggests).","Normalize inputs at the boundary: `if '://' not in url: url = 'https://' + url` before making requests.","If using a base URL from config, validate it at startup (e.g. with `urllib.parse.urlparse(url).scheme`) and fail fast with a clear config error."],"exampleFix":"# before\nrequests.get('api.example.com/v1/users')\n\n# after\nrequests.get('https://api.example.com/v1/users')","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\nparsed = urlparse(url)\nif not parsed.scheme:\n    url = \"https://\" + url","typeGuard":null,"tryCatchPattern":"from requests.exceptions import MissingSchema\ntry:\n    resp = requests.get(url)\nexcept MissingSchema:\n    resp = requests.get(\"https://\" + url)","preventionTips":["Normalize user-supplied URLs by prepending https:// when urlparse shows no scheme","Catch requests.exceptions.MissingSchema specifically, not bare ValueError","Validate URLs at input boundaries (form/CLI parsing), not at request time"],"tags":["python","requests","url","missing-schema","validation"],"analyzedSha":"414f0513c33883adf6f2b46901d4f0b38a455851","analyzedAt":"2026-07-31T19:24:57.696Z","schemaVersion":2}