{"record":{"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/6a6b581b48225afa0b76912d1028c6035baee932/redis/connection.py#L1173-L1209","documentation":"Raised in on_connect (connection.py:1187-1191) on the RESP3 path when HELLO succeeds (no auth case) but the returned handshake 'proto' field does not equal the requested protocol. The server claimed to negotiate HELLO 3 but reported a different proto number in its reply, indicating the server did not actually switch to the requested RESP version. Treated as a connection failure.","triggerScenarios":"Connecting with protocol=3 to a server that accepts HELLO but echoes back a different proto (misbehaving proxy, RESP3-incompatible middleware, or a server that silently downgrades); a man-in-the-middle/transparent proxy rewriting HELLO responses.","commonSituations":"HAProxy/Envoy/Nginx in front of Redis that doesn't forward HELLO correctly; Redis versions with RESP3 bugs; connecting through a sharding proxy that strips HELLO metadata.","solutions":["Bypass the proxy and connect directly to a Redis node to confirm RESP3 works there.","Fall back to protocol=2 if the intermediary cannot carry RESP3 correctly.","Upgrade the proxy/middleware to one that transparently forwards HELLO.","Upgrade Redis to a version with correct HELLO/proto reporting."],"exampleFix":"# before\nr = redis.Redis(host='proxy', port=6379, protocol=3)\n# after\nr = redis.Redis(host='redis-node-0', port=6379, protocol=3)","handlingStrategy":"fallback","validationCode":"# Detect a non-conforming intermediary before relying on RESP3\ndef negotiate_protocol(host, port):\n    r = redis.Redis(host=host, port=port, protocol=3)\n    try:\n        r.ping()\n        return 3\n    except redis.exceptions.ConnectionError as e:\n        if 'Invalid RESP version' in str(e):\n            return 2  # proxy can't carry RESP3\n        raise\n\nr = redis.Redis(host=h, port=p, protocol=negotiate_protocol(h, p))","typeGuard":"null","tryCatchPattern":"from redis.exceptions import ConnectionError\ntry:\n    r = redis.Redis(host=h, port=p, protocol=3)\n    r.ping()\nexcept ConnectionError as e:\n    if 'Invalid RESP version' in str(e):\n        r = redis.Redis(host=h, port=p, protocol=2)  # fallback\n    else:\n        raise","preventionTips":["Test RESP3 against the real endpoint (through any proxy) before standardising on protocol=3.","Keep a protocol=2 fallback in config for misbehaving proxies.","Upgrade proxy/middleware that mangles HELLO responses."],"tags":["protocol","resp3","hello","proxy","connection"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}