{"id":"fed515a28a64aaa8","repo":"redis/redis-py","slug":"invalid-username-or-password-fed515","errorCode":null,"errorMessage":"Invalid Username or Password","messagePattern":"Invalid Username or Password","errorType":"exception","errorClass":"AuthenticationError","httpStatus":null,"severity":"critical","filePath":"redis/connection.py","lineNumber":1176,"sourceCode":"            # ) != self.protocol:\n            #     raise ConnectionError(\"Invalid RESP version\")\n        elif auth_args:\n            # avoid checking health here -- PING will fail if we try\n            # to check the health prior to the AUTH\n            self.send_command(\"AUTH\", *auth_args, check_health=False)\n\n            try:\n                auth_response = self.read_response()\n            except AuthenticationWrongNumberOfArgsError:\n                # a username and password were specified but the Redis\n                # server seems to be < 6.0.0 which expects a single password\n                # arg. retry auth with just the password.\n                # https://github.com/andymccurdy/redis-py/issues/1274\n                self.send_command(\"AUTH\", auth_args[-1], check_health=False)\n                auth_response = self.read_response()\n\n            if str_if_bytes(auth_response) != \"OK\":\n                raise AuthenticationError(\"Invalid Username or Password\")\n\n        # if resp version is specified, switch to it\n        elif check_protocol_version(self.protocol, 3):\n            if isinstance(self._parser, _RESP2Parser):\n                self.set_parser(_RESP3Parser)\n                # update cluster exception classes\n                self._parser.EXCEPTION_CLASSES = parser.EXCEPTION_CLASSES\n                self._parser.on_connect(self)\n            self.send_command(\"HELLO\", self.protocol, check_health=check_health)\n            self.handshake_metadata = self.read_response()\n            if (\n                self.handshake_metadata.get(b\"proto\") != self.protocol\n                and self.handshake_metadata.get(\"proto\") != self.protocol\n            ):\n                raise ConnectionError(\"Invalid RESP version\")\n\n        # Activate maintenance notifications for this connection\n        # if enabled in the configuration","sourceCodeStart":1158,"sourceCodeEnd":1194,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L1158-L1194","documentation":"Raised as an AuthenticationError during the on_connect handshake when the AUTH command succeeds at the protocol level but the server returns a non-'OK' response, indicating the credentials were rejected. This is distinct from a connection-level error: the socket is fine, but the username/password combination is wrong.","triggerScenarios":"Connecting with redis.Redis(password='wrong') or an incorrect username against an ACL-protected Redis 6+ server. The library sends AUTH, reads the response, and since it is not 'OK' (the server replies with an error that gets normalized), AuthenticationError is raised.","commonSituations":"Wrong password in config/env vars; rotated credentials not updated; default user password set via CONFIG SET requirepass but client still using old value; ACL user disabled or password changed.","solutions":["Verify the password/username against the server (CONFIG GET requirepass or ACL GETUSER).","Update stale credentials in your config/secrets manager.","If using ACL, confirm the user exists and has the correct password hash.","Ensure you are not passing a username to a Redis < 6.0 server that only expects a password."],"exampleFix":"// before\nr = redis.Redis(host=h, username='default', password='old-pass')\nr.ping()\n// after\nr = redis.Redis(host=h, username='default', password='correct-pass')\nr.ping()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from redis.exceptions import AuthenticationError\ntry:\n    r = redis.Redis(host=h, username=u, password=p)\n    r.ping()\nexcept AuthenticationError:\n    # credentials wrong: surface to user / rotate credentials\n    raise","preventionTips":["Store credentials in a secrets manager and rotate cleanly.","Test auth with a PING at startup and fail fast with a clear message.","Verify ACL user/password on the server before deploying."],"tags":["authentication","security","connection"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}