8

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."',)})
MadsVJ
  • 678
  • 6
  • 19
  • 1
    try connecting to cassandra using same host and credentials from cqlsh to see if it works... `cqlsh 12345.mycompany.net -u fancycar -p becauseimbatman` – undefined_variable Jun 07 '17 at 10:16
  • @undefined_variable Thanks for the suggestion. That gives me an error: `[root@12345.mycompany.net SYST:~]# cqlsh 12345.mycompany.net -u fancycar -p becauseimbatman ` `Connection error: ('Unable to connect to any servers', {'11.111.11.11': error(None, "Tried connecting to [('11.111.11.11', 9042)]. Last error: timed out")})` Whereas logging in "as usual" works: `[root@12345.mycompany.net SYST:~]# cqlsh -u fancycar -p becauseimbatman` `Connected to 12345_cluster at 12345.mycompany.net:9042. [cqlsh 5.0.1 | Cassandra 3.0.11.1485 | DSE 5.0.5 | CQL spec 3.4.0 | Native protocol v4]` – MadsVJ Jun 07 '17 at 10:26
  • 1
    your second command connects to localhost while first connect to remote server.. does 12345.mycompany.net resolve to same host as localhost? – undefined_variable Jun 07 '17 at 10:31
  • Alright. I tried again, and now your @undefined_variable suggestion actually works.. What should be my next step? – MadsVJ Jun 07 '17 at 11:12
  • you might want to have look in rpc_address and listen_address in cassandra.yaml – undefined_variable Jun 07 '17 at 13:38
  • In order to connect to cassandra from remote host.. 2 things must be ensured.. 1) you should be able to connect from remote host to cassandra host (`telnet cassandra-host 9042`)... 2) `rpc_address` should not be localhost in cassandra.yaml – undefined_variable Jun 12 '17 at 07:48

1 Answers1

3

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]
MadsVJ
  • 678
  • 6
  • 19