{"record":{"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":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":1792,"sourceCode":"            \"Redis URL must specify one of the following schemes \"\n            \"(redis://, rediss://, unix://)\"\n        )\n\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    else:  # implied:  parsed.scheme in (\"redis\", \"rediss\")\n        if parsed.hostname:\n            kwargs[\"host\"] = unquote(parsed.hostname)\n        if parsed.port:","sourceCodeStart":1774,"sourceCodeEnd":1810,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/connection.py#L1774-L1810","documentation":"Raised as ValueError from parse_url() when a registered URL query parameter fails to coerce via its parser (int/float/to_bool/parse_ssl_verify_flags). The message reports the offending parameter name. parse_qs already percent-decodes values, so the parser sees the raw token; if int('abc') or to_bool(bad) raises TypeError/ValueError, the URL is rejected.","triggerScenarios":"Passing ?db=abc, ?socket_timeout=fast, ?protocol=3.5, ?ssl_check_hostname=yes, ?max_connections=many, or an unparsable verify-flags list. Any non-numeric db/timeout/protocol or non-bool boolean triggers it.","commonSituations":"Typo in a numeric query param; passing 'yes'/'no'/'on'/'off' (only a limited FALSE_STRINGS set is honored: 0/F/FALSE/N/NO); negative or fractional values where int is required (db, protocol); URL-encoding mishandling.","solutions":["Use numeric values for db/protocol/max_connections/socket_read_size/health_check_interval.","For booleans use true/false (or one of 0/F/FALSE/N/NO for false; anything else is truthy).","Validate/normalize the URL at config-load time before passing to from_url.","For verify flags, pass ssl.VerifyFlags constants directly instead of a URL string."],"exampleFix":"// before\nr = redis.asyncio.from_url('redis://host?db=two&ssl_check_hostname=yes')\n// after\nr = redis.asyncio.from_url('redis://host?db=2&ssl_check_hostname=true')","handlingStrategy":"validation","validationCode":"from urllib.parse import parse_qs\n\ndef validate_query_params(url: str) -> dict:\n    numeric = {'db', 'socket_timeout', 'socket_connect_timeout', 'socket_read_size',\n               'max_connections', 'health_check_interval', 'ssl_min_version',\n               'protocol', 'timeout'}\n    boolish = {'socket_keepalive', 'retry_on_timeout', 'ssl_check_hostname', 'legacy_responses'}\n    out = {}\n    for k, vs in parse_qs(urlparse(url).query).items():\n        v = vs[0]\n        if k in numeric:\n            out[k] = (int if k in {'db','socket_read_size','max_connections','health_check_interval','protocol','ssl_min_version'} else float)(v)\n        elif k in boolish:\n            out[k] = v.lower() not in ('0','f','false','n','no')\n        else:\n            out[k] = v\n    return out","typeGuard":"def is_bad_query_value(exc: BaseException) -> bool:\n    return isinstance(exc, ValueError) and 'connection URL' in str(exc)","tryCatchPattern":"try:\n    r = redis.asyncio.from_url(url)\nexcept ValueError as e:\n    if 'connection URL' in str(e):\n        # log and fall back to defaults\n        r = redis.asyncio.Redis(host=h)\n    else:\n        raise","preventionTips":["Use numeric tokens for db/protocol/timeouts.","Use true/false for boolean query params.","Prefer explicit kwargs over URL query params for non-trivial config."],"tags":["url","config","validation","query-param","async"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}