redis/redis-py · error · ConnectionError

Invalid RESP version

Error message

Invalid RESP version

What it means

Raised as a ConnectionError during the HELLO handshake when the server-negotiated RESP protocol version (the 'proto' field in the HELLO reply) does not equal the version the client requested (3). This means the server downgraded or refused the requested protocol, signaling an incompatible or unexpected negotiation outcome.

Source

Thrown at redis/connection.py:1191

                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
        # This is a no-op if maintenance notifications are not enabled
        self.activate_maint_notifications_handling_if_enabled(check_health=check_health)

        # if a client_name is given, set it
        if self.client_name:
            self.send_command(
                "CLIENT",
                "SETNAME",
                self.client_name,
                check_health=check_health,
            )
            if str_if_bytes(self.read_response()) != "OK":
                raise ConnectionError("Error setting client name")

        # Set the library name and version from driver_info

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Upgrade the Redis server to a version that supports HELLO/RESP3 (6.0+).
  2. Fall back to protocol=2 if RESP3 negotiation is unreliable in your environment.
  3. Remove intermediaries that alter the HELLO response.

Example fix

// before
r = redis.Redis(host=h, protocol=3)
r.ping()
// after
r = redis.Redis(host=h, protocol=2)
r.ping()
Defensive patterns

Strategy: try-catch

Validate before calling

import redis
info = redis.Redis(host=h).info()  # check server version first
ver = info['redis_version']
protocol = 3 if tuple(map(int, ver.split('.'))) >= (6, 0, 0) else 2

Try / catch

try:
    r = redis.Redis(host=h, protocol=3)
    r.ping()
except redis.exceptions.ConnectionError as e:
    if 'Invalid RESP version' in str(e):
        r = redis.Redis(host=h, protocol=2)
        r.ping()

Prevention

When it happens

Trigger: Requesting protocol=3 via HELLO against a server that responds with a different proto number (e.g. an old server or a proxy that mangles the HELLO response). Triggered in on_connect after send_command('HELLO', self.protocol) and read_response().

Common situations: Redis version < 6.0 that does not understand HELLO; a network proxy/load balancer rewriting or stripping the HELLO response; connecting through an intermediary that forces RESP2; mismatched server/client expectations.

Related errors


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