How can we connect to remote Cassandra server with python driver

1.1k views Asked by At

I am trying to connect to Cassandra with the python driver:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

auth_provider = PlainTextAuthProvider(username='yyyy',password='zzzzz')
cluster = Cluster(['xx.xx.xx.xx'], control_connection_timeout=10,  port=9042,auth_provider=auth_provider)
session = cluster.connect()

Error:

NoHostAvailable: ('Unable to connect to any servers', {'xx.xx.xx.xx:9042': ConnectionRefusedError(111, "Tried connecting to [('xx.xx.xx.xx ', 9042)]. Last error: Connection refused")}) 

I have also set rpc address in yaml file : 0.0.0.0

1

There are 1 answers

0
Erick Ramirez On

Chances are port 9042 is bound to the private IP of your nodes because you set:

rpc_address: 0.0.0.0

You need to set the the rpc_address to the nodes' public IP or an IP that is reachable remotely by your application server. Typically you should have:

listen_address: private_ip
rpc_address: public_ip

If it helps, I've provided some additional details in this post -- https://community.datastax.com/questions/6019/. Cheers!