我试图从我的python代码连接运行协议2的Cassandra 2数据库:
def auth_provider(ip):
return dict(username=cassandra_username,
password=cassandra_password)
def cassandradb():
cluster = Cluster(cassandra_cluster,
load_balancing_policy=RoundRobinPolicy(),
port=cassandra_port,
auth_provider=auth_provider)
session = cluster.connect(cassandra_keyspace)
...
代码引发了异常:
cassandra.cluster.NoHostAvailable:
('Unable to connect to any servers',
{'127.0.0.1': UnsupportedOperation('Credentials-based authentication
is not supported with protocol version 2 or higher. Use the SASL
authentication mechanism instead.',)})
我从未与SASL
合作过。我应该如何更改auth_provider
或其他代码?
答案 0 :(得分:0)
https://datastax-oss.atlassian.net/browse/PYTHON-73
基于SASL的身份验证尚未在Python Driver 2.x中实现。您可以使用1.x驱动程序版本,该版本适用于所有最近的cassandra版本。
答案 1 :(得分:0)
最近修补了驱动程序的主分支。以下是工作示例:
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
auth_provider = PlainTextAuthProvider(username='cassandra',
password='cassandra')
cluster = Cluster(auth_provider=auth_provider)