{"record":{"id":"1b6c6baf05b6fc3d","repo":"redis/redis-py","slug":"get-node-requires-one-of-the-following-1-node-na","errorCode":null,"errorMessage":"get_node requires one of the following: 1. node name 2. host and port","messagePattern":"get_node requires one of the following: 1\\. node name 2\\. host and port","errorType":"exception","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/cluster.py","lineNumber":2050,"sourceCode":"            self._event_dispatcher = EventDispatcher()\n        else:\n            self._event_dispatcher = event_dispatcher\n\n    def get_node(\n        self,\n        host: Optional[str] = None,\n        port: Optional[int] = None,\n        node_name: Optional[str] = None,\n    ) -> Optional[\"ClusterNode\"]:\n        if host and port:\n            # the user passed host and port\n            if host == \"localhost\":\n                host = socket.gethostbyname(host)\n            return self.nodes_cache.get(get_node_name(host=host, port=port))\n        elif node_name:\n            return self.nodes_cache.get(node_name)\n        else:\n            raise DataError(\n                \"get_node requires one of the following: 1. node name 2. host and port\"\n            )\n\n    def set_nodes(\n        self,\n        old: Dict[str, \"ClusterNode\"],\n        new: Dict[str, \"ClusterNode\"],\n        remove_old: bool = False,\n    ) -> None:\n        if remove_old:\n            for name in list(old.keys()):\n                if name not in new:\n                    # Node is removed from cache before disconnect starts,\n                    # so it won't be found in lookups during disconnect\n                    # Mark active connections so in-flight commands can\n                    # finish, then disconnect them when their current\n                    # operation completes. Free connections can be\n                    # disconnected immediately.","sourceCodeStart":2032,"sourceCodeEnd":2068,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/cluster.py#L2032-L2068","documentation":"Raised as a DataError by NodesFlagsCache.get_node() when the caller supplies neither a node_name nor a host+port pair. The lookup needs at least one of those identifiers to index into nodes_cache, so an empty call is treated as a programmer error rather than returning a misleading None.","triggerScenarios":"Calling cluster.get_node() with no arguments, or with only one of host/port (e.g. get_node(host='localhost')). The method requires either both host and port or a node_name.","commonSituations":"Wrapping get_node in helper code that conditionally passes kwargs and ends up passing none; typo'd keyword (host= vs hostname=, name= vs node_name=).","solutions":["Pass node_name= returned from an existing node's .name attribute.","Pass both host= and port= together.","Check parameter names exactly: host, port, node_name (not 'name' or 'hostname').","If you want any default node, use cluster.get_default_node() instead."],"exampleFix":"// before\nnode = cluster.get_node()\n\n// after\nnode = cluster.get_node(host='localhost', port=7000)\n# or\nnode = cluster.get_node(node_name='localhost:7000')","handlingStrategy":"validation","validationCode":"def lookup_node(cluster, host=None, port=None, node_name=None):\n    if node_name:\n        return cluster.get_node(node_name=node_name)\n    if host and port:\n        return cluster.get_node(host=host, port=port)\n    return cluster.get_default_node()  # fallback instead of raising","typeGuard":"null","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    node = cluster.get_node(**kwargs)\nexcept DataError as e:\n    if 'get_node requires' in str(e):\n        node = cluster.get_default_node()","preventionTips":["Always pass either node_name or both host and port to get_node().","Use cluster.get_default_node() when you just need any node.","Validate that at least one identifier was supplied in wrapper helpers."],"tags":["cluster","nodes","api-usage","dataerror"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}