CassioML/cassio

Error in connecting to astra db

Opened this issue · 0 comments

import os

import cassio
import dotenv

dotenv.load_dotenv()

cassio.init(
    database_id=os.environ.get("ASTRA_DB_ID", ""),
    token=os.environ.get("ASTRA_DB_APPLICATION_TOKEN", ""),
    keyspace=os.environ.get("ASTRA_DB_KEYSPACE", ""),
)

Running the above codes leads to the following error

Traceback (most recent call last):
  File "/Users/nanwang/Codes/nan-wang/rag_demo/toy4.py", line 8, in <module>
    cassio.init(
  File "/Users/nanwang/Codes/nan-wang/rag_demo/.venv/lib/python3.10/site-packages/cassio/config/__init__.py", line 306, in init
    default_session = cluster.connect()
  File "cassandra/cluster.py", line 1717, in cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 1753, in cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 1740, in cassandra.cluster.Cluster.connect
  File "cassandra/cluster.py", line 3543, in cassandra.cluster.ControlConnection.connect
  File "cassandra/cluster.py", line 3588, in cassandra.cluster.ControlConnection._reconnect_internal
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'XXX-us-east-2.db.astra.datastax.com:XXX': OperationTimedOut('errors=Timed out creating connection (5 seconds), last_host=None')

In the error logs, I noticed that XXX-us-east-2.db.astra.datastax.com is different from the API endpoints I got from the Astra, which is
https://XXX-us-east-2.apps.astra.datastax.com. And the following codes work, where i set

import os
import dotenv

from astrapy import DataAPIClient


dotenv.load_dotenv()

# Initialize the client
client = DataAPIClient(os.environ.get("ASTRA_DB_APPLICATION_TOKEN", ""))
db = client.get_database_by_api_endpoint(
    api_endpoint="https://XXX-us-east-2.apps.astra.datastax.com",
    namespace=os.environ.get("ASTRA_DB_KEYSPACE", ""),
)

print(f"Connected to Astra DB: {db.list_collection_names()}")

cassio==0.1.8
Python 3.10.13
Darwin MacBook-Pro-8.local 23.5.0 Darwin Kernel Version 23.5.0