In week 3 (option 1), I was unable to test db_connection.py and Ex02_Connect_to_Cassandra.py codes in the terminal. I have also installed Cassandra-driver using 'pip' command. I also used gitpod to execute but I encountered the same error there. So kindly help me solve this issue in connecting my Cassandra!!
This is my db_connection.py code:
#!/usr/bin/env python3 from cassandra.cluster import Cluster from cassandra.auth import PlainTextAuthProvider # This is the Zip file you downloaded SECURE_CONNECT_BUNDLE = 'F:\education\project data\Cassandra\Cassandra Workshop series\Session materials\cassandra-workshop-series-master updated\cassandra-workshop-series-master\week3-AppDev-crud\crud-python/secure-connect-killrvideocluster.zip' # This is the username, recommended value was KVUser USERNAME = "KVUser"; # This is the password, recommended value was KVPassword PASSWORD = "KVPassword"; # This is the keyspace name, recommended value was killrvideo KEYSPACE = "killrvideo"; class Connection: def __init__(self): self.secure_connect_bundle=SECURE_CONNECT_BUNDLE self.path_to_creds='' self.cluster = Cluster( cloud={ 'secure_connect_bundle': self.secure_connect_bundle }, auth_provider=PlainTextAuthProvider(USERNAME, PASSWORD) ) self.session = self.cluster.connect(KEYSPACE) def close(self): self.cluster.shutdown() self.session.shutdown()
This is my Ex02_Connect_to_Cassandra.py code:
#!/usr/bin/env python3 from db_connection import Connection print('========================================') print('Start exercise') try: connection = Connection() output = connection.session.execute("SELECT * FROM system.local") for row in output: print("Your are now connected to cluster '%s'", row.cluster_name) except: print('Failure') else: print('Success') finally: print('Closing connection (up to 10s)') connection.close() print('========================================')