ynv_2006_193227 avatar image
ynv_2006_193227 asked bettina.swynnerton answered

Python Connectivity in VM

Hi, Trying to run Datastax Examples on Github for python in VM, unable to connect to Cassandra database. Queries are not returning any error but i think there is a connection issue. Can you please help here.


Below are the connection details which I was using in my VM

def create_connection():    
# cluster details from nodetool status
    cluster = Cluster([''])       
    return cluster.connect('demo')

After execution of this, when trying to insert new user into the table

def set_user(session, lastname, age, city, email, firstname):    
    session.execute("INSERT INTO demo.users (lastname, age, city, email, firstname) VALUES (%s,%s,%s,%s,%s)", ['Yan', 20, 'London', '', 'Vani'])

Not getting any execution error but table was not updated, which shows connection issue.

Do I need to import any libraries here?

python driver
10 |1000

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

bettina.swynnerton avatar image bettina.swynnerton ♦♦ commented ·

Hi @ynv_2006_193227,

would you add a few more details to your question?

i.e. which example are you running, what is the cluster topology on your VM (for example, your nodetool status output) and how you are setting up the connection in the python code, i.e, your Cluster object, contact points, etc.

Are you experimenting with one of the Academy VMs? If so, which one?


0 Likes 0 ·
ynv_2006_193227 avatar image ynv_2006_193227 bettina.swynnerton ♦♦ commented ·

[Update posted in the question above]

0 Likes 0 ·
Erick Ramirez avatar image Erick Ramirez ♦♦ ynv_2006_193227 commented ·

Will you please respond to all the points that Bettina raised? There isn't enough info to answer your question. Cheers!

0 Likes 0 ·

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered


as Erick mentioned, it is still not enough information to understand exactly what is going on here.

However, I would expect the way you declare the contact points to throw an unresolvable contact point error. I am not sure why you are not seeing an error though.

Here is a simple connection test:

from cassandra.cluster import Cluster
cluster = Cluster([''], port=9041)

session = cluster.connect()


Note that you need to define the port separately.

I am using port 9041 here, as this is the setup on the DS201 VM. By default this would be port 9042.

This is using the latest cassandra-driver.

Let us know how you get on.

10 |1000

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