{"id":"7fb9ecf297444df5","repo":"redis/redis-py","slug":"invalid-value-for-name-in-connection-url","errorCode":null,"errorMessage":"Invalid value for '{name}' in connection URL.","messagePattern":"Invalid value for '(.+?)' in connection URL\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":1783,"sourceCode":"    path: str\n\n\ndef parse_url(url: str) -> ConnectKwargs:\n    parsed: ParseResult = urlparse(url)\n    kwargs: ConnectKwargs = {}\n\n    for name, value_list in parse_qs(parsed.query).items():\n        if value_list and len(value_list) > 0:\n            # parse_qs() already percent-decodes query values, so use the value\n            # as-is; unquoting again here would double-decode (e.g. \"%2520\" ->\n            # \"%20\" -> \" \"). See issue #4208.\n            value = value_list[0]\n            parser = URL_QUERY_ARGUMENT_PARSERS.get(name)\n            if parser:\n                try:\n                    kwargs[name] = parser(value)\n                except (TypeError, ValueError):\n                    raise ValueError(f\"Invalid value for '{name}' in connection URL.\")\n            else:\n                kwargs[name] = value\n\n    if parsed.username:\n        kwargs[\"username\"] = unquote(parsed.username)\n    if parsed.password:\n        kwargs[\"password\"] = unquote(parsed.password)\n\n    # We only support redis://, rediss:// and unix:// schemes.\n    if parsed.scheme == \"unix\":\n        if parsed.path:\n            kwargs[\"path\"] = unquote(parsed.path)\n        kwargs[\"connection_class\"] = UnixDomainSocketConnection\n\n    elif parsed.scheme in (\"redis\", \"rediss\"):\n        if parsed.hostname:\n            kwargs[\"host\"] = unquote(parsed.hostname)\n        if parsed.port:","sourceCodeStart":1765,"sourceCodeEnd":1801,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/connection.py#L1765-L1801","documentation":"Raised as a ValueError from parse_url() when a recognized URL query parameter (db, socket_timeout, socket_connect_timeout, protocol, health_check_interval, etc.) fails its typed parser (int/float/to_bool/parse_ssl_verify_flags) with TypeError or ValueError. The name of the offending query key is reported. Unknown keys are passed through as strings and do not trigger this.","triggerScenarios":"A redis:// or rediss:// URL with a query param that has a typed parser but a malformed value: ?db=abc (int parse fails), ?socket_timeout=fast (float fails), ?protocol=three (int fails), ?ssl_min_version= (int fails), ?health_check_interval=-x.","commonSituations":"Typos in query values; copy-paste from docs with placeholders left in; environment-variable interpolation that left an empty or non-numeric value; passing 'true'/'false' to a non-bool param like db or protocol.","solutions":["Inspect the named query param in the URL and correct its value to the expected type (int/float/bool).","For booleans use 0/1 or true/false (handled by to_bool).","Remove the param to fall back to the library default rather than passing garbage.","Validate the URL with urllib.parse_qs before passing it to from_url."],"exampleFix":"// before\nr = redis.asyncio.from_url(\"redis://host:6379?socket_timeout=fast&protocol=three\")\n\n// after\nr = redis.asyncio.from_url(\"redis://host:6379?socket_timeout=1.5&protocol=3\")","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse, parse_qs\nTYPED_PARAMS = {\"db\": int, \"socket_timeout\": float, \"socket_connect_timeout\": float,\n    \"socket_read_size\": int, \"max_connections\": int, \"health_check_interval\": int,\n    \"ssl_min_version\": int, \"protocol\": int, \"timeout\": float}\ndef validate_redis_url(url: str) -> None:\n    for k, vs in parse_qs(urlparse(url).query).items():\n        if k in TYPED_PARAMS:\n            TYPED_PARAMS[k](vs[0])  # raises on bad value","typeGuard":null,"tryCatchPattern":"try:\n    r = redis.asyncio.from_url(url)\nexcept ValueError as e:\n    if \"Invalid value for\" in str(e):\n        # strip typed query params and pass them as kwargs instead\n        r = redis.asyncio.from_url(base_url, socket_timeout=1.5)\n    else:\n        raise","preventionTips":["Pre-validate typed query params before from_url.","Keep URLs in config, not interpolated ad-hoc.","Use kwargs for typed values to get clearer errors."],"tags":["url-parsing","config","validation","async"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}