redis/redis-py · error · ConnectionError

Invalid RESP version

Error message

Invalid RESP version

What it means

Raised as ConnectionError during the HELLO/AUTH handshake when the client requests a specific RESP protocol via HELLO but the server's reply reports a different proto version (response.get(b'proto')/('proto') != int(self.protocol)). The server did not agree to the requested RESP version, so the connection is unusable in the negotiated shape.

Source

Thrown at redis/asyncio/connection.py:976

            # we need to send them via HELLO
        if auth_args and 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)
            if len(auth_args) == 1:
                auth_args = ["default", auth_args[0]]
            # avoid checking health here -- PING will fail if we try
            # to check the health prior to the AUTH
            await self.send_command(
                "HELLO", self.protocol, "AUTH", *auth_args, check_health=False
            )
            response = await self.read_response()
            if response.get(b"proto") != int(self.protocol) and response.get(
                "proto"
            ) != 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")

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Upgrade the Redis server to a version that supports the requested RESP protocol (>=6.0 for RESP3).
  2. Match the client protocol to what the server supports (protocol=2 for older servers).
  3. Remove any proxy between client and server that mangles HELLO responses.

Example fix

// before
client = Redis(url='redis://old-redis:6379', protocol=3)  # raises [98]
// after
client = Redis(url='redis://old-redis:6379', protocol=2)
Defensive patterns

Strategy: validation

Validate before calling

# Check server version/HELLO support before forcing protocol
info = await client.info('server')
if protocol == 3 and tuple(map(int, info['redis_version'].split('.'))) < (6, 0, 0):
    raise ValueError('Server too old for RESP3')

Try / catch

from redis.exceptions import ConnectionError
try:
    client = Redis(url=url, protocol=3)
    await client.ping()
except ConnectionError as e:
    if 'Invalid RESP version' in str(e):
        client = Redis(url=url, protocol=2)

Prevention

When it happens

Trigger: Connecting with protocol=3 to a Redis server that only supports RESP2 (e.g. Redis < 6.0), or with protocol=2 when the server forces a different version; an upstream/proxy that rewrites the HELLO reply.

Common situations: Local dev against an old Redis; a proxy (Twemproxy, Envoy, a cloud proxy) that strips HELLO; mismatched client/server major versions.

Related errors


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