{"id":"52d14d9da87c7cee","repo":"redis/redis-py","slug":"redis-url-must-specify-one-of-the-following-scheme","errorCode":null,"errorMessage":"Redis URL must specify one of the following schemes ({valid_schemes})","messagePattern":"Redis URL must specify one of the following schemes \\((.+?)\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":1817,"sourceCode":"        if parsed.hostname:\n            kwargs[\"host\"] = unquote(parsed.hostname)\n        if parsed.port:\n            kwargs[\"port\"] = int(parsed.port)\n\n        # If there's a path argument, use it as the db argument if a\n        # querystring value wasn't specified\n        if parsed.path and \"db\" not in kwargs:\n            try:\n                kwargs[\"db\"] = int(unquote(parsed.path).replace(\"/\", \"\"))\n            except (AttributeError, ValueError):\n                pass\n\n        if parsed.scheme == \"rediss\":\n            kwargs[\"connection_class\"] = SSLConnection\n\n    else:\n        valid_schemes = \"redis://, rediss://, unix://\"\n        raise ValueError(\n            f\"Redis URL must specify one of the following schemes ({valid_schemes})\"\n        )\n\n    return kwargs\n\n\n_CP = TypeVar(\"_CP\", bound=\"ConnectionPool\")\n\n\nclass ConnectionPoolInterface(ABC):\n    @abstractmethod\n    def get_protocol(self):\n        pass\n\n    @abstractmethod\n    def reset(self) -> None:\n        pass\n","sourceCodeStart":1799,"sourceCodeEnd":1835,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/connection.py#L1799-L1835","documentation":"Raised as a ValueError from parse_url() when the URL scheme is not one of 'redis', 'rediss', or 'unix'. The valid schemes string lists redis://, rediss://, unix://. Anything else (http://, rediss, missing ://, typos like redi://) lands in the else branch at line 1815.","triggerScenarios":"Calling redis.asyncio.from_url(url) / Redis.from_url with a URL whose scheme is unrecognized: 'http://host', 'redi://host', 'rediss:host' (no //), 'tcp://host', an empty string, or a URL with no scheme at all.","commonSituations":"Env var misconfiguration (REDIS_URL=http://...); missing '://' ; typo in scheme; copying a URI from another database (postgres://, mongodb://) into a Redis config; secret-manager injecting the wrong format.","solutions":["Use exactly 'redis://' (plaintext), 'rediss://' (TLS), or 'unix://' (UDS) as the scheme.","Double-check environment variables / config files that supply the URL.","Strip whitespace/newlines from the URL before passing it.","Log the scheme before constructing the client during debugging."],"exampleFix":"// before\nr = redis.asyncio.from_url(\"http://localhost:6379\")\n\n// after\nr = redis.asyncio.from_url(\"redis://localhost:6379\")","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\nVALID_SCHEMES = {\"redis\", \"rediss\", \"unix\"}\ndef valid_redis_url(url: str) -> bool:\n    return urlparse(url).scheme in VALID_SCHEMES","typeGuard":"def is_redis_scheme_url(url: str) -> bool:\n    from urllib.parse import urlparse\n    return urlparse(url).scheme in (\"redis\", \"rediss\", \"unix\")","tryCatchPattern":"try:\n    r = redis.asyncio.from_url(url)\nexcept ValueError as e:\n    if \"must specify one of the following schemes\" in str(e):\n        r = redis.asyncio.Redis(host=\"localhost\", port=6379)  # sane default\n    else:\n        raise","preventionTips":["Assert the URL scheme in config/startup before constructing the client.","Centralize REDIS_URL validation.","Beware secret-manager / env-var injection of wrong schemes."],"tags":["url-parsing","config","validation","async"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}