redis/redis-py · critical · AuthenticationError

Invalid Username or Password

Error message

Invalid Username or Password

What it means

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.

Source

Thrown at redis/connection.py:1176

            # ) != self.protocol:
            #     raise ConnectionError("Invalid RESP version")
        elif auth_args:
            # avoid checking health here -- PING will fail if we try
            # to check the health prior to the AUTH
            self.send_command("AUTH", *auth_args, check_health=False)

            try:
                auth_response = self.read_response()
            except AuthenticationWrongNumberOfArgsError:
                # a username and password were specified but the Redis
                # server seems to be < 6.0.0 which expects a single password
                # arg. retry auth with just the password.
                # https://github.com/andymccurdy/redis-py/issues/1274
                self.send_command("AUTH", auth_args[-1], check_health=False)
                auth_response = self.read_response()

            if str_if_bytes(auth_response) != "OK":
                raise AuthenticationError("Invalid Username or Password")

        # if resp version is specified, switch to it
        elif check_protocol_version(self.protocol, 3):
            if isinstance(self._parser, _RESP2Parser):
                self.set_parser(_RESP3Parser)
                # update cluster exception classes
                self._parser.EXCEPTION_CLASSES = parser.EXCEPTION_CLASSES
                self._parser.on_connect(self)
            self.send_command("HELLO", self.protocol, check_health=check_health)
            self.handshake_metadata = self.read_response()
            if (
                self.handshake_metadata.get(b"proto") != self.protocol
                and self.handshake_metadata.get("proto") != self.protocol
            ):
                raise ConnectionError("Invalid RESP version")

        # Activate maintenance notifications for this connection
        # if enabled in the configuration

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Verify the password/username against the server (CONFIG GET requirepass or ACL GETUSER).
  2. Update stale credentials in your config/secrets manager.
  3. If using ACL, confirm the user exists and has the correct password hash.
  4. Ensure you are not passing a username to a Redis < 6.0 server that only expects a password.

Example fix

// before
r = redis.Redis(host=h, username='default', password='old-pass')
r.ping()
// after
r = redis.Redis(host=h, username='default', password='correct-pass')
r.ping()
Defensive patterns

Strategy: try-catch

Try / catch

from redis.exceptions import AuthenticationError
try:
    r = redis.Redis(host=h, username=u, password=p)
    r.ping()
except AuthenticationError:
    # credentials wrong: surface to user / rotate credentials
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/fed515a28a64aaa8.json. Report an issue: GitHub.