gpt4 book ai didi

python - 使用 DseAuthenticator 和 DseAuthorizer 从 Windows 将 python 连接到 cassandra 集群

转载 作者:IT王子 更新时间:2023-10-29 00:22:14 24 4
gpt4 key购买 nike

我已经尝试过使用 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]

关于python - 使用 DseAuthenticator 和 DseAuthorizer 从 Windows 将 python 连接到 cassandra 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44406371/

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