使用 DseAuthenticator 和 DseAuthorizer 从 windows 连接 python 到 cassandra 集群

Connecting python to cassandra a cluster from windows with DseAuthenticator and DseAuthorizer

我已经尝试过 pycassacassandra.clusterdse.cluster,但都没有建立连接。

我觉得我连接到错误的主机,因为我正在写 linux 服务器主机名,但没有指定任何关于 cassandra 的信息。

同事告诉我他们只知道通过 linux 机器上的 cqlsh 内联连接到服务器。这听起来很不方便。

具体配置在cassandra.yaml

authenticator: com.datastax.bdp.cassandra.auth.DseAuthenticator
authorizer: com.datastax.bdp.cassandra.auth.DseAuthorizer

我在 pycassa 做什么:

import pycassa
URIPORTLIST = ['12345.mycompany.net:9420']
pool = pycassa.ConnectionPool('my_keyspace', server_list=URIPORTLIST,credentials={'USERNAME':'fancycar','PASSWORD':'becauseimbatman'}, prefill=False)
cf = pycassa.ColumnFamily(pool, 'my_table')

错误信息:

AllServersUnavailable: An attempt was made to connect to each of the servers twice, but none of the attempts succeeded. The last failure was TTransportException: Could not connect to 12345.mycompany.net:9420

dse.cluster

from dse.cluster import Cluster
auth_provider = PlainTextAuthProvider(
        username='fancycar', password='becauseimbatman')
cluster = Cluster(
    ['12345.mycompany.net'],
    port=9042,auth_provider=auth_provider)
session = cluster.connect('my_keyspace')

错误信息:

NoHostAvailable: ('Unable to connect to any servers', {'11.111.11.1': AuthenticationFailed('Failed to authenticate to 11.111.11.2: Error from server: code=0100 [Bad credentials] message="Failed to login. Please re-try."',)})

已通过使用 dse.auth PlainTextAuthProvider 而不是 Cassandra 修复..

from dse.cluster import Cluster
# pip install dse-driver
from dse.auth import PlainTextAuthProvider
auth_provider = PlainTextAuthProvider(
        username='fancycar', password='becauseimbatman ')
cluster = Cluster(contact_points=['12345.mycompany.net'],
port=9042, auth_provider=auth_provider)
session = cluster.connect('batcave')
print "connected"
print session.execute("SELECT * FROM robinstears")[0]