Search code examples
cassandradatastaxdatastax-astracassandra-drivercassandra-python-driver

Can't connect to Astra DB with Python driver


I believe I'm doing exactly as mentioned in the documentation Python-driver-AstraDB

cloud_config= {
        'secure_connect_bundle': 'secure-connect-test-warehouse.zip'
}

logging.basicConfig(level=logging.DEBUG)

auth_provider = PlainTextAuthProvider(my_id, my_secret)
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()

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

I get the following error :

File "connect_database.py", line 23, in <module>
    session = cluster.connect()
  File "cassandra/cluster.py", line 1677, in cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 1713, in cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 1700, in cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 3507, in cassandra.cluster.ControlConnection.connect
  File "cassandra/cluster.py", line 3552, in cassandra.cluster.ControlConnection._reconnect_internal
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers
OSError(101, "Tried connecting to [('...', ..., 0, 0)]. Last error: Network is unreachable")})

I suspect Network is unreachable has to do with network latency I tried to set Cluster(cloud=cloud_config, auth_provider=auth_provider,control_connection_timeout=10) default of control_connection_timeout is 2.0, yet I get the same issue.

if correct how can I solve this ?


Solution

  • The documentation says to use the absolute path of the Secure Connect Bundle (SCB) as follows,

    cloud_config= {
            'secure_connect_bundle': '/path/to/secure-connect-database_name.zip'
    }
    

    NOTE: Set the cloud_config parameter for the Cluster initialization as shown in the following example. The secure_connect_bundle must include the absolute path to your Astra DB database credentials (secure-connect-database_name.zip).

    In which case, your code should look as below,

    ...
    cloud_config= {
            'secure_connect_bundle': '/your_path/to/secure-connect-test-warehouse.zip'
    }
    ...
    

    Cheers!