使用DseAuthenticator和DseAuthorizer

时间:2017-06-07 07:35:47

标签: python linux cassandra cql cqlsh

我已尝试使用pycassacassandra.clusterdse.cluster,但没有建立连接。

我觉得我正在连接错误的主机,因为我正在编写linux服务器主机名而没有指定任何有关cassandra的内容。

Collegues告诉我他们只知道通过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."',)})

1 个答案:

答案 0 :(得分:2)

通过使用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]