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

annie.wangliu_182215 avatar image
annie.wangliu_182215 asked ·

How do I connect Cassandra in Jupyter notebook In Anaconda with Python?

I have installed cassandra-driver through pip,

! pip install cassandra-driver

Then import also works

import Cassandra

But connect to DB, which doesn't work

from cassandra.cluster import Cluster
try:     cluster = Cluster(['127.0.0.1'])     session = cluster.connect()
except Exception as e:    print(e)

The error message is:

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

I have googled a lot, can't figure out where the problem is, and think it might because of the config:

JAVA_HOME is as:

c:\program files\Java\jdk_13.0.2

Cassandra is under:

C:\Users\xx\anaconda3\Lib\site-packages

I am not good at the config. May I ask whether there is a specific requirement for the config?

I work on it in Jupyter Notebook in Anaconda.

Thanks.

python driver
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 ·

The error you posted indicates that you're trying to connect to a Cassandra instance running on localhost. However, I imagine that your Cassandra instance isn't running in Anaconda.

In any case, the error clearly states that the connection was refused on localhost:

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

You need to specify a public IP (rpc_address) for at least one of the nodes in the cluster that the driver can connect to.

For more info, see the Getting Started with the Python driver. Cheers!

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.