{"record":{"id":"d4e51ea90cb9fee2","repo":"redis/redis-py","slug":"error-setting-client-name","errorCode":null,"errorMessage":"Error setting client name","messagePattern":"Error setting client name","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":1025,"sourceCode":"            #     raise ConnectionError(\"Invalid RESP version\")\n\n        # Activate maintenance notifications for this connection\n        # if enabled in the configuration\n        # This is a no-op if maintenance notifications are not enabled\n        await self.activate_maint_notifications_handling_if_enabled(\n            check_health=check_health\n        )\n\n        # if a client_name is given, set it\n        if self.client_name:\n            await self.send_command(\n                \"CLIENT\",\n                \"SETNAME\",\n                self.client_name,\n                check_health=check_health,\n            )\n            if str_if_bytes(await self.read_response()) != \"OK\":\n                raise ConnectionError(\"Error setting client name\")\n\n        # Set the library name and version from driver_info, pipeline for lower startup latency\n        lib_name_sent = False\n        lib_version_sent = False\n\n        if self.driver_info and self.driver_info.formatted_name:\n            await self.send_command(\n                \"CLIENT\",\n                \"SETINFO\",\n                \"LIB-NAME\",\n                self.driver_info.formatted_name,\n                check_health=check_health,\n            )\n            lib_name_sent = True\n\n        if self.driver_info and self.driver_info.lib_version:\n            await self.send_command(\n                \"CLIENT\",","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/connection.py#L1007-L1043","documentation":"Raised as a generic ConnectionError during on_connect() when CLIENT SETNAME <self.client_name> returns anything other than 'OK'. The library only sets the name if client_name was configured; a non-OK reply typically means an ACL restriction or a server that rejected the name. The handshake aborts and the connection is not usable.","triggerScenarios":"Constructing redis.asyncio.Redis(client_name='my-app') (or setting client_name_class / pool client name) and connecting to a server whose ACL user lacks permission to run CLIENT SETNAME, or rejects the name value (e.g. contains invalid bytes).","commonSituations":"ACL user scoped with -client or renamed_commands blocking CLIENT; very old Redis server (< 2.6.9 where CLIENT SETNAME was introduced); a client_name containing spaces or newlines that the server rejects.","solutions":["Grant the ACL user +client permission (or use a user with +@all).","Remove or simplify the client_name to confirm it is the cause, then re-add a sanitized value.","Upgrade the Redis server to >= 2.6.9.","If the name is only for diagnostics, move identification to LIB-NAME via driver_info instead."],"exampleFix":"// before\nr = redis.asyncio.Redis(host=h, client_name='my app name')\n// after\nr = redis.asyncio.Redis(host=h, client_name='my-app-name')","handlingStrategy":"validation","validationCode":"import redis.asyncio as aioredis\n\nasync def supports_client_setname(url: str, name: str) -> bool:\n    r = aioredis.from_url(url)\n    try:\n        await r.execute_command('CLIENT', 'SETNAME', name)\n        return True\n    except Exception:\n        return False\n    finally:\n        await r.aclose()","typeGuard":"from redis.exceptions import ConnectionError\n\ndef is_client_name_error(exc: BaseException) -> bool:\n    return isinstance(exc, ConnectionError) and 'client name' in str(exc).lower()","tryCatchPattern":"from redis.exceptions import ConnectionError\n\ntry:\n    client = redis.asyncio.Redis(host=h, client_name=name)\n    await client.ping()\nexcept ConnectionError as e:\n    if 'client name' in str(e).lower():\n        client = redis.asyncio.Redis(host=h)  # drop client_name\n    else:\n        raise","preventionTips":["Confirm the ACL user has +client (or +@all) before relying on client_name.","Keep client_name short, alphanumeric, no spaces.","If unsure the server supports CLIENT SETNAME, set client_name only after a capability check."],"tags":["client-name","acl","connection","async","handshake"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}