Simoyw
Simoyw

Reputation: 691

I can't connect to Cassandra with DataStax Python driver

I'm having trouble connecting to Cassandra (running on an EC2 node) locally with DataStax Python driver for Cassandra: (similar to this question)

from cassandra.cluster import Cluster
cluster = Cluster(['127.0.0.1'], port=9042)
cluster.connect()

I get:

cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None',)})

The same if i run:

cluster = Cluster(['127.0.0.1'], port=9160)
cluster.connect()

The service seems to listen in the correct port:

netstat -nltp | grep 9042 (No info could be read for "-p": geteuid()=1000 but you should be root.) tcp6 0 0 127.0.0.1:9042 :::* LISTEN -

Also the command cqlsh 127.0.0.1 9042 work perfectly.

I have the default settings on file cassandra.yaml:

start_native_transport: true
native_transport_port: 9042
rpc_address: localhost
rpc_port: 9160

I also tried to change the rpc_address with the PRIVATE_IP of my ec2 instance but nothing changed.

I don't use PyCharm, I use the interactive console of python on my instance.

Can somebody explain to me what I'm doing wrong?

Thanks

Upvotes: 3

Views: 1147

Answers (2)

Emanuel George Hategan
Emanuel George Hategan

Reputation: 1263

As described here as well:

I've learned that the gevent module interferes with the cassandra-driver

  • cassandra-driver (3.10)
  • gevent (1.1.1)

Uninstalling gevent solved the problem for me

pip uninstall gevent

Upvotes: 0

Simoyw
Simoyw

Reputation: 691

Resolved by reinstalling cassandra using the DataStax Community AMI on Amazon AWS. Probably was a problem of versions of Cassandra and Datastax python driver.

Upvotes: 1

Related Questions