{"record":{"id":"170de481b66b5878","repo":"redis/redis-py","slug":"protocol-must-be-either-2-or-3","errorCode":null,"errorMessage":"protocol must be either 2 or 3","messagePattern":"protocol must be either 2 or 3","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":704,"sourceCode":"        self.redis_connect_func = redis_connect_func\n        self._reader: Optional[asyncio.StreamReader] = None\n        self._writer: Optional[asyncio.StreamWriter] = None\n        self._socket_read_size = socket_read_size\n        self._active_read_timeout = None\n        self._connect_callbacks: List[weakref.WeakMethod[ConnectCallbackT]] = []\n        self._buffer_cutoff = 6000\n        self._re_auth_token: Optional[TokenInterface] = None\n        self._should_reconnect = False\n\n        try:\n            p = int(protocol)\n        except TypeError:\n            p = DEFAULT_RESP_VERSION\n        except ValueError:\n            raise ConnectionError(\"protocol must be an integer\")\n        else:\n            if p < 2 or p > 3:\n                raise ConnectionError(\"protocol must be either 2 or 3\")\n        self.protocol = p\n        self.legacy_responses = legacy_responses\n        if parser_class != _AsyncHiredisParser:\n            # The Python parsers are protocol-specific; hiredis supports both.\n            if self.protocol == 3 and parser_class == _AsyncRESP2Parser:\n                parser_class = _AsyncRESP3Parser\n            elif self.protocol == 2 and parser_class == _AsyncRESP3Parser:\n                parser_class = _AsyncRESP2Parser\n        self.set_parser(parser_class)\n\n        # HIMPORT client-side state. `himport_registry` is the shared client-level\n        # registry (empty if unconfigured) and persists across reconnects.\n        self.himport_registry = himport_registry\n        self._reset_himport_state()\n\n        AsyncMaintNotificationsAbstractConnection.__init__(\n            self,\n            maint_notifications_config,","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/connection.py#L686-L722","documentation":"ConnectionError from the async Connection constructor (redis/asyncio/connection.py:703) when the parsed integer protocol is outside the supported range (only 2 or 3 are valid). RESP 1 is obsolete and RESP >3 does not exist, so any other integer is rejected up front.","triggerScenarios":"`Redis(protocol=1)`, `Redis(protocol=4)`, `Redis(protocol=0)`.","commonSituations":"Misconfigured protocol env var set to an unsupported value; assuming a newer RESP version exists.","solutions":["Use protocol=3 (current default) or protocol=2","Leave protocol unset to accept the default","Fix the upstream config value"],"exampleFix":"// before\nRedis(protocol=4)\n// after\nRedis(protocol=3)","handlingStrategy":"validation","validationCode":"if protocol not in (2, 3):\n    raise ValueError('protocol must be 2 or 3')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use 2 or 3 for protocol","Validate protocol from config before constructing the client"],"tags":["async","connection","resp3","config","validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}