{"id":"975cf63ef94737eb","repo":"redis/redis-py","slug":"invalid-username-or-password","errorCode":null,"errorMessage":"Invalid Username or Password","messagePattern":"Invalid Username or Password","errorType":"exception","errorClass":"AuthenticationError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":993,"sourceCode":"            ) != int(self.protocol):\n                raise ConnectionError(\"Invalid RESP version\")\n        # avoid checking health here -- PING will fail if we try\n        # to check the health prior to the AUTH\n        elif auth_args:\n            await self.send_command(\"AUTH\", *auth_args, check_health=False)\n\n            try:\n                auth_response = await 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                await self.send_command(\"AUTH\", auth_args[-1], check_health=False)\n                auth_response = await 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, _AsyncRESP2Parser):\n                self.set_parser(_AsyncRESP3Parser)\n                # update cluster exception classes\n                self._parser.EXCEPTION_CLASSES = parser.EXCEPTION_CLASSES\n                self._parser.on_connect(self)\n            await self.send_command(\"HELLO\", self.protocol, check_health=check_health)\n            response = await self.read_response()\n            # if response.get(b\"proto\") != self.protocol and response.get(\n            #     \"proto\"\n            # ) != self.protocol:\n            #     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","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/connection.py#L975-L1011","documentation":"Raised as AuthenticationError during the non-HELLO AUTH path when the server's AUTH reply is anything other than 'OK'. The credentials supplied were rejected (wrong password, wrong user, or ACL mismatch), so the connection is aborted.","triggerScenarios":"Connecting with username/password that the Redis ACL does not recognize; using the wrong default-user password; connecting to a Redis that requires AUTH without supplying it (server returns an error); password contains trailing whitespace/newline from env copy.","commonSituations":"Rotated/expired passwords, typo'd credentials in env vars, connecting to a secured Redis with no ACL entry for the user, copy-paste artifacts (quotes/newlines) in secrets.","solutions":["Verify the username/password against the server's ACL (ACL GETUSER / redis-cli AUTH).","Check env var loading for trailing whitespace, quotes, or newlines around the password.","Ensure you're connecting to the intended Redis instance (wrong host can have different creds).","If using RESP3, note AUTH runs inside HELLO — confirm the user has access on the default or specified protocol."],"exampleFix":"// before\nclient = Redis(username='svc', password=os.environ['REDIS_PASS'])  # trailing newline -> raises [99]\n// after\nclient = Redis(username='svc', password=os.environ['REDIS_PASS'].strip())","handlingStrategy":"validation","validationCode":"# Validate credentials out-of-band before constructing the client\nimport redis\nok = False\ntry:\n    r = redis.Redis(host=h, port=p, username=u, password=pw)\n    r.ping(); ok = True\nexcept redis.exceptions.AuthenticationError:\n    ok = False","typeGuard":null,"tryCatchPattern":"from redis.exceptions import AuthenticationError\ntry:\n    await client.ping()\nexcept AuthenticationError:\n    # surface a clean login error to the user; check ACL/env for stray whitespace","preventionTips":["Strip whitespace/newlines from passwords loaded via env vars.","Verify the ACL user exists and has the needed permissions.","Confirm you're connecting to the intended Redis instance."],"tags":["connection","auth","credentials","acl","security"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}