{"id":"313e23c2a41db5bc","repo":"redis/redis-py","slug":"readonly-command-failed-313e23","errorCode":null,"errorMessage":"READONLY command failed","messagePattern":"READONLY command failed","errorType":"exception","errorClass":"ConnectionError","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":1026,"sourceCode":"                    # Client was already disconnected. do nothing\n                    pass\n\n    def on_connect(self, connection):\n        \"\"\"\n        Initialize the connection, authenticate and select a database and send\n         READONLY if it is set during object initialization.\n        \"\"\"\n        connection.on_connect()\n\n        if self.read_from_replicas or self.load_balancing_strategy:\n            # Sending READONLY command to server to configure connection as\n            # readonly. Since each cluster node may change its server type due\n            # to a failover, we should establish a READONLY connection\n            # regardless of the server type. If this is a primary connection,\n            # READONLY would not affect executing write commands.\n            connection.send_command(\"READONLY\")\n            if str_if_bytes(connection.read_response()) != \"OK\":\n                raise ConnectionError(\"READONLY command failed\")\n\n        if self.user_on_connect_func is not None:\n            self.user_on_connect_func(connection)\n\n    def get_redis_connection(self, node: \"ClusterNode\") -> Redis:\n        if not node.redis_connection:\n            with self._lock:\n                if not node.redis_connection:\n                    self.nodes_manager.create_redis_connections([node])\n        return node.redis_connection\n\n    def get_node(self, host=None, port=None, node_name=None):\n        return self.nodes_manager.get_node(host, port, node_name)\n\n    def get_primaries(self):\n        return self.nodes_manager.get_nodes_by_server_type(PRIMARY)\n\n    def get_replicas(self):","sourceCodeStart":1008,"sourceCodeEnd":1044,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/cluster.py#L1008-L1044","documentation":"Error \"READONLY command failed\" thrown in redis/redis-py.","triggerScenarios":"Thrown at redis/cluster.py:1026 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}