{"id":"f07ca63348e9d2e4","repo":"redis/redis-py","slug":"invalid-value-for-name-in-connection-url-f07ca6","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/connection.py","lineNumber":2355,"sourceCode":"            \"Redis URL must specify one of the following \"\n            \"schemes (redis://, rediss://, unix://)\"\n        )\n\n    url = urlparse(url)\n    kwargs = {}\n\n    for name, value in parse_qs(url.query).items():\n        if value and len(value) > 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[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 url.username:\n        kwargs[\"username\"] = unquote(url.username)\n    if url.password:\n        kwargs[\"password\"] = unquote(url.password)\n\n    # We only support redis://, rediss:// and unix:// schemes.\n    if url.scheme == \"unix\":\n        if url.path:\n            kwargs[\"path\"] = unquote(url.path)\n        kwargs[\"connection_class\"] = UnixDomainSocketConnection\n\n    else:  # implied:  url.scheme in (\"redis\", \"rediss\"):\n        if url.hostname:\n            kwargs[\"host\"] = unquote(url.hostname)\n        if url.port:","sourceCodeStart":2337,"sourceCodeEnd":2373,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L2337-L2373","documentation":"Raised as a ValueError by parse_url (connection.py:2352-2355) when a recognized query-string parameter fails its typed parser. URL_QUERY_ARGUMENT_PARSERS (lines 2310-2327) maps param names to converters (int, float, to_bool, parse_ssl_verify_flags, list); any TypeError or ValueError from the converter is caught and re-raised with this generic message naming the offending parameter.","triggerScenarios":"A rediss:// or redis:// URL whose query string has a malformed value for a typed param, e.g. ?db=abc (int fails), ?socket_timeout=fast (float fails), ?protocol=three (int fails), ?max_connections=many, ?ssl_min_version=x. The {name} in the message identifies which parameter.","commonSituations":"Config typos in templated URLs or env vars; passing booleans as non-canonical strings that to_bool still accepts (those won't raise) but numeric fields with text will; URL-encoding issues where a placeholder wasn't substituted (e.g. ?db=${DB} left literal).","solutions":["Read the {name} in the error message to identify the offending parameter, then correct its value to the expected type (int/float/bool).","For numeric params (db, socket_timeout, protocol, max_connections, health_check_interval, socket_read_size, ssl_min_version, timeout) use plain numeric strings.","Substitute all template placeholders in the URL before passing it; log the final URL (redacting credentials) to confirm.","Validate critical values in your config loader before building the URL."],"exampleFix":"# before\nurl = \"redis://h:6379?protocol=three&db=zero\"\nredis.Redis.from_url(url)  # Invalid value for 'protocol'\n\n# after\nurl = \"redis://h:6379?protocol=3&db=0\"\nredis.Redis.from_url(url)","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse, parse_qs\nTYPED = {\"db\",\"socket_timeout\",\"socket_connect_timeout\",\"socket_read_size\",\n         \"max_connections\",\"health_check_interval\",\"ssl_min_version\",\n         \"protocol\",\"timeout\"}\ndef validate_url_values(url: str):\n    q = parse_qs(urlparse(url).query)\n    for k, vals in q.items():\n        if k in TYPED and vals:\n            try:\n                int(vals[0]) if k in {\"db\",\"socket_read_size\",\"max_connections\",\n                 \"health_check_interval\",\"ssl_min_version\",\"protocol\"} else float(vals[0])\n            except ValueError:\n                raise ValueError(f\"Query param {k}={vals[0]!r} is not numeric\")\n    return url","typeGuard":"def url_query_value_is_valid(name: str, value: str) -> bool:\n    numeric = {\"db\",\"socket_read_size\",\"max_connections\",\"health_check_interval\",\"ssl_min_version\",\"protocol\"}\n    floats = {\"socket_timeout\",\"socket_connect_timeout\",\"timeout\"}\n    try:\n        if name in numeric: int(value)\n        elif name in floats: float(value)\n    except ValueError:\n        return False\n    return True","tryCatchPattern":"try:\n    client = redis.Redis.from_url(url)\nexcept ValueError as e:\n    if \"Invalid value for\" in str(e):\n        # name is in the message; re-derive URL with corrected value\n        client = redis.Redis.from_url(fixed_url)\n    else:\n        raise","preventionTips":["Render config templates fully before passing URLs; never leave literal placeholders.","Validate numeric query params in your config loader.","Log the final URL (minus credentials) at startup for quick diagnosis."],"tags":["configuration","url-parsing","validation","connection"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}