Problems with the connection of cassandra in droplets

I'm installing cassandra db in a droplet from Digital Ocean using the following guide: https://www.digitalocean.com/community/tutorials/how-to-install-cassandra-and-run-a-single-node-cluster-on-ubuntu-22-04 However, when I try to connect with it using cqlsh appear:

root@ubuntu-s-cass-history-chat:~# cqlsh
Traceback (most recent call last):
  File "/usr/bin/cqlsh.py", line 134, in <module>
    from cassandra.cluster import Cluster
  File "/usr/share/cassandra/lib/cassandra-driver-internal-only-3.25.0.zip/cassandra-driver-3.25.0/cassandra/cluster.py", line 33, in <module>
ModuleNotFoundError: No module named 'six.moves'

I tried to installing six with apt-get install python3-six, but persist the message.`

¿What could it be?

Also, if I try to connect to the cassandra database remotely from my PC using python and the cassandra-driver library appears:

NoHostAvailable: ('Unable to connect to any servers', {'host:port': ConnectionRefusedError(10061, "Tried connecting to [('host', port)]. Last error: Unable to establish a connection since the computer destination expressly denied said connection")})

To try the connection I use the following code:

from cassandra.cluster import Cluster
cluster = Cluster([host], port=port)
session = cluster.connect()

Upvotes: 1

Views: 167

Answers (1)

Aaron
Aaron

Reputation: 57748

No module named 'six.moves'

So that error happens when running cqlsh on Python 3.12. Downgrade or set a custom Python version for the Cassandra bin/ directory (using pyenv) to Python 3.9. That version should work.

Tried connecting to [('host', port)]

First of all, the driver defaults to the default port of 9042. Don't change that. In fact, don't even list it in your code; just define your Cluster like this:

cluster = Cluster([host]) 

What is the value of host? Is it 127.0.0.1? If Cassandra is bound to localhost/127.0.0.1, it will only be able to accept local connections. No other machine will be able to connect to it.

Anyway, I would first figure out what the value of host is. Put a print("host={0}".format(host)) in your code and make sure of that.

You'll also want to make sure that host is set to the reachable IP address that Cassandra is bound to. You can figure that out with this command:

grep _address conf/cassandra.yaml | grep -v "#"

It should produce output that looks something like this:

listen_address: 10.1.2.120
rpc_address: 33.70.150.101

Upvotes: 1

Related Questions