redis/redis-py · error · AuthenticationError

Invalid Username or Password

Error message

Invalid Username or Password

What it means

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.

Source

Thrown at redis/asyncio/connection.py:993

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

            try:
                auth_response = await 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
                await self.send_command("AUTH", auth_args[-1], check_health=False)
                auth_response = await 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, _AsyncRESP2Parser):
                self.set_parser(_AsyncRESP3Parser)
                # update cluster exception classes
                self._parser.EXCEPTION_CLASSES = parser.EXCEPTION_CLASSES
                self._parser.on_connect(self)
            await self.send_command("HELLO", self.protocol, check_health=check_health)
            response = await self.read_response()
            # if response.get(b"proto") != self.protocol and response.get(
            #     "proto"
            # ) != self.protocol:
            #     raise ConnectionError("Invalid RESP version")

        # Activate maintenance notifications for this connection
        # if enabled in the configuration
        # This is a no-op if maintenance notifications are not enabled

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Verify the username/password against the server's ACL (ACL GETUSER / redis-cli AUTH).
  2. Check env var loading for trailing whitespace, quotes, or newlines around the password.
  3. Ensure you're connecting to the intended Redis instance (wrong host can have different creds).
  4. If using RESP3, note AUTH runs inside HELLO — confirm the user has access on the default or specified protocol.

Example fix

// before
client = Redis(username='svc', password=os.environ['REDIS_PASS'])  # trailing newline -> raises [99]
// after
client = Redis(username='svc', password=os.environ['REDIS_PASS'].strip())
Defensive patterns

Strategy: validation

Validate before calling

# Validate credentials out-of-band before constructing the client
import redis
ok = False
try:
    r = redis.Redis(host=h, port=p, username=u, password=pw)
    r.ping(); ok = True
except redis.exceptions.AuthenticationError:
    ok = False

Try / catch

from redis.exceptions import AuthenticationError
try:
    await client.ping()
except AuthenticationError:
    # surface a clean login error to the user; check ACL/env for stray whitespace

Prevention

When it happens

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

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

Related errors


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