我想使用python驱动程序从cassandra数据库连接。
我可以使用cassandra驱动程序进行连接,但在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条答案
按热度按时间esbemjvw1#
为了避免这些警告,你应该遵循他们的建议。以下是有关它们的其他详细信息:
第一个建议指定负载平衡策略。在代码段中,您将其配置为“无”,这与根本不配置它相同。更喜欢根据集群配置显式配置它。例子:
第二个只是说您应该删除auth\u提供程序配置,因为您连接到的集群/节点没有启用身份验证。