{"record":{"id":"944430898c6d862f","repo":"redis/redis-py","slug":"protocol-must-be-an-integer","errorCode":null,"errorMessage":"protocol must be an integer","messagePattern":"protocol must be an integer","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/connection.py","lineNumber":701,"sourceCode":"        self.health_check_interval = health_check_interval\n        self.next_health_check: float = -1\n        self.encoder = encoder_class(encoding, encoding_errors, decode_responses)\n        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","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/connection.py#L683-L719","documentation":"ConnectionError from the async Connection constructor (redis/asyncio/connection.py:701) when int(protocol) raises ValueError - i.e. protocol is a non-numeric string. The protocol argument must be coercible to an integer (2 or 3). A non-numeric value is rejected early rather than failing later during HELLO negotiation.","triggerScenarios":"`Redis(protocol='three')`, `Redis(protocol='2.7')` (float-string), or any protocol value that int() cannot parse.","commonSituations":"Reading protocol from an env var or config file as a string typo; passing the string form of the version.","solutions":["Pass an integer: Redis(protocol=3)","Validate/convert config strings to int before passing: int(os.environ['REDIS_PROTOCOL'])","Leave protocol unset to use the library default (DEFAULT_RESP_VERSION=3)"],"exampleFix":"// before\nRedis(protocol=os.environ.get('REDIS_PROTOCOL', '3'))\n// after\nRedis(protocol=int(os.environ.get('REDIS_PROTOCOL', 3)))","handlingStrategy":"validation","validationCode":"try:\n    protocol = int(protocol)\nexcept (TypeError, ValueError):\n    protocol = 3  # or raise a clear config error","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Coerce protocol to int from any string config source","Leave protocol unset to use the default when unsure"],"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"}