{"id":"94cf415663e7716f","repo":"redis/redis-py","slug":"invalid-resp-version-94cf41","errorCode":null,"errorMessage":"Invalid RESP version","messagePattern":"Invalid RESP version","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":1191,"sourceCode":"                auth_response = 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, _RESP2Parser):\n                self.set_parser(_RESP3Parser)\n                # update cluster exception classes\n                self._parser.EXCEPTION_CLASSES = parser.EXCEPTION_CLASSES\n                self._parser.on_connect(self)\n            self.send_command(\"HELLO\", self.protocol, check_health=check_health)\n            self.handshake_metadata = self.read_response()\n            if (\n                self.handshake_metadata.get(b\"proto\") != self.protocol\n                and self.handshake_metadata.get(\"proto\") != self.protocol\n            ):\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\n        self.activate_maint_notifications_handling_if_enabled(check_health=check_health)\n\n        # if a client_name is given, set it\n        if self.client_name:\n            self.send_command(\n                \"CLIENT\",\n                \"SETNAME\",\n                self.client_name,\n                check_health=check_health,\n            )\n            if str_if_bytes(self.read_response()) != \"OK\":\n                raise ConnectionError(\"Error setting client name\")\n\n        # Set the library name and version from driver_info","sourceCodeStart":1173,"sourceCodeEnd":1209,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L1173-L1209","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Upgrade the Redis server to a version that supports HELLO/RESP3 (6.0+).","Fall back to protocol=2 if RESP3 negotiation is unreliable in your environment.","Remove intermediaries that alter the HELLO response."],"exampleFix":"// before\nr = redis.Redis(host=h, protocol=3)\nr.ping()\n// after\nr = redis.Redis(host=h, protocol=2)\nr.ping()","handlingStrategy":"try-catch","validationCode":"import redis\ninfo = redis.Redis(host=h).info()  # check server version first\nver = info['redis_version']\nprotocol = 3 if tuple(map(int, ver.split('.'))) >= (6, 0, 0) else 2","typeGuard":null,"tryCatchPattern":"try:\n    r = redis.Redis(host=h, protocol=3)\n    r.ping()\nexcept redis.exceptions.ConnectionError as e:\n    if 'Invalid RESP version' in str(e):\n        r = redis.Redis(host=h, protocol=2)\n        r.ping()","preventionTips":["Confirm the server supports HELLO/RESP3 before requesting protocol=3.","Fall back to RESP2 if intermediaries mangle the HELLO response."],"tags":["protocol","resp3","connection","handshake"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}