{"record":{"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":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":2370,"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":2352,"sourceCodeEnd":2388,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/connection.py#L2352-L2388","documentation":"Raised as ValueError(f\"Invalid value for '{name}' in connection URL.\") by parse_url when a query-string parameter registered in URL_QUERY_ARGUMENT_PARSERS cannot be coerced by its typed parser. The per-name parsers (int for db/max_connections/health_check_interval/protocol/ssl_min_version, float for socket_timeout/socket_connect_timeout/timeout, to_bool, list, parse_ssl_verify_flags) raise TypeError or ValueError on bad input, which parse_url re-wraps into this message.","triggerScenarios":"A URL like redis://host?db=abc (int parse fails), ?socket_timeout=fast (float parse fails), ?max_connections=many, ?protocol=three, or ?ssl_min_version=foo. Any query key in URL_QUERY_ARGUMENT_PARSERS whose value does not match its parser.","commonSituations":"Typing numeric query params as words. Passing an enum name where an int is expected (ssl_min_version expects the integer TLS version). Misconfigured env vars or templated URLs that interpolate non-numeric values.","solutions":["Check the offending query param and give it a value of the right type (db=0, socket_timeout=2.5, protocol=3, etc.).","For ssl_min_version pass the integer value of ssl.TLSVersion (e.g. ssl.TLSVersion.TLSv1_3.value).","Validate/escape templated URLs before they reach from_url."],"exampleFix":"# before\nr = redis.Redis.from_url('redis://host?socket_timeout=fast&db=two')\n# after\nr = redis.Redis.from_url('redis://host?socket_timeout=2.5&db=2')","handlingStrategy":"try-catch","validationCode":"from redis.connection import URL_QUERY_ARGUMENT_PARSERS\n\ndef validate_query_values(url: str) -> None:\n    from urllib.parse import urlparse, parse_qs\n    parsed = parse_qs(urlparse(url).query)\n    for name, vals in parsed.items():\n        parser = URL_QUERY_ARGUMENT_PARSERS.get(name)\n        if parser and vals:\n            try:\n                parser(vals[0])\n            except (TypeError, ValueError):\n                raise ValueError(f'Query param {name!r}={vals[0]!r} is invalid for parser {parser.__name__}')","typeGuard":null,"tryCatchPattern":"try:\n    r = redis.Redis.from_url(url)\nexcept ValueError as e:\n    if 'Invalid value for' in str(e):\n        # log the bad param and fall back to a known-good URL without query params\n        r = redis.Redis.from_url(strip_query_params(url))\n    else:\n        raise","preventionTips":["Type-check numeric query params before they reach from_url.","Prefer passing explicit kwargs (db=, socket_timeout=) over URL query params for dynamic values.","Escape templated URLs and validate them in tests."],"tags":["configuration","url-parsing","validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}