Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've tried both with pycassa, cassandra.cluster and dse.cluster without making a connection.

I feel like I'm connecting to the wrong host, as I'm writing the linux servers hostname and not specifying anything regarding the cassandra.

Collegues have told me they only know of connecting to the server through cqlsh inline on the linux machine. That just sounds unconvinient.

Specific configurations in cassandra.yaml

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

What I'm doing in 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')

Error message:

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

With 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')

Error message:

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."',)})
like image 243
MadsVJ Avatar asked Jun 07 '17 07:06

MadsVJ


People also ask

How does Python read data from Cassandra?

Fastest way to read Cassandra data into pandas with automatic iteration of pages. Create dictionary and add each to it by automatically iterating all pages. Then, create dataframe with this dictionary. Show activity on this post.


1 Answers

Fixed by using the dse.auth PlainTextAuthProvider instead of the Cassandra one..

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]
like image 133
MadsVJ Avatar answered Nov 14 '22 23:11

MadsVJ