Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

DL avatar image
DL asked Erick Ramirez commented

Cannot connect to DSE from Python app

I am having some difficulty in connecting to a Centos 7.x server hosted DataStax Cassandra 6.8.

I am able to successfully connect locally inside the Centos Shell and the nodetool status shows the cluster Up and Normal.

Things I tried in cassandra.yaml file -

changed the listen_address parameter from localhost to the IP address of the server. Result -> DSE is not starting.

Commented the listen_address line. Result -> DSE is not starting

Left the parameter of listen_address blank. Result -> DSE in not starting.

as mentioned above - OS - CentOS 7 DSE Version - 6.8 Install method RPM

Python program -

#cluster = Cluster()
cluster = Cluster(['192.168.1.223'])

# To establish connection and begin executing queries, need a session
session = cluster.connect()

row = session.execute("select release_version from system.local;").one()
if row:
    print(row[0])
else:
    print("An error occurred.")

Exception thrown from python ->

NoHostAvailable: ('Unable to connect to any servers', {'192.168.1.223:9042': ConnectionRefusedError(10061, "Tried connecting to [('192.168.1.223', 9042)]. Last error: No connection could be made because the target machine actively refused it")})

Both my PC and my server are on the same network and I am able to ping from each other.

Any help is highly appreciated.

Thanks

installation
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

This error indicates that you are connecting to a node which is not listening for CQL connections on IP 192.168.1.223 and CQL port 9042:

No connection could be made because the target machine actively refused it

The 2 most likely causes are:

  1. DSE is not running
  2. DSE isn't listening for client connections on the right IP

You indicated already that you are not able to start DSE. You'll need to review the logs located in /var/log/cassandra by default for clues as to why it's not running.

The other possible issue is that you haven't configured native_transport_address (rpc_address in open-source Cassandra). You need to set this to an IP address that is accessible to clients (your app) otherwise, it will default to localhost (127.0.0.1).

In cassandra.yaml, configure the node with:

listen_address: private_ip
native_transport_address: public_ip

If you are just testing it on a local network, set both properties to the server's IP address. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Hi @Erick Ramirez , thanks for the suggestion.
0 Likes 0 ·
You're welcome. Cheers!
0 Likes 0 ·