gpt4 book ai didi

python-3.x - 连接 Cassandra 和 Python 的有效方法(抑制警告)

转载 作者:行者123 更新时间:2023-12-05 03:56:53 26 4
gpt4 key购买 nike

我想使用 python 驱动程序从 Cassandra 数据库连接。

我可以使用 cassandra-driver 连接,但是当我在 pycharm 中运行代码时我有几个警告:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider


server_config = {
"host": "172.XX.XX.XX",
"port": "9042",
"user": "XXXXXXXXX",
"password": "XXXXXXXX",
"keySpace": "XXXXXX"
}


keyspace = server_config['keySpace']

auth_provider = PlainTextAuthProvider(username=server_config['user'],password=server_config['password'])

node_ips = [server_config['host']]



cluster = Cluster(contact_points=node_ips, load_balancing_policy=None, port=int(server_config['port']), auth_provider=auth_provider, protocol_version=3)

session = cluster.connect()

session.set_keyspace(keyspace)


但是我有几个警告:

WARNING:cassandra.cluster:Cluster.__init__ called with contact_points specified, but no load_balancing_policy. In the next major version, this will raise an error; please specify a load-balancing policy. (contact_points = ['172.18.64.19'], lbp = None)

WARNING:cassandra.connection:An authentication challenge was not sent, this is suspicious because the driver expects authentication (configured authenticator = PlainTextAuthenticator)
INFO:cassandra.policies:Using datacenter 'datacenter1' for DCAwareRoundRobinPolicy (via host '172.18.64.19'); if incorrect, please specify a local_dc to the constructor, or limit contact points to local cluster nodes

WARNING:cassandra.connection:An authentication challenge was not sent, this is suspicious because the driver expects authentication (configured authenticator = PlainTextAuthenticator)

如何更有效地联系?

谢谢!

最佳答案

要避免这些警告,您应该遵循他们的建议。以下是关于它们的更多详细信息:

  1. 第一个建议指定负载平衡策略。在您的代码片段中,您将其配置为 None,这与根本不配置它是一样的。最好根据您的集群配置明确配置它。示例:

# This example assume that *datacenter1* if a valid DC for your cluster.
Cluster(contact_points=node_ips,
load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='datacenter1'),
port=int(server_config['port']),
auth_provider=auth_provider,
protocol_version=3)

  1. 第二个只是说您应该删除 auth_provider 配置,因为您要连接的集群/节点没有启用身份验证。

关于python-3.x - 连接 Cassandra 和 Python 的有效方法(抑制警告),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58957973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com