0

Currently I am learning about Astra DB from this youtube link https://www.youtube.com/watch?v=NyDT3KkscSk&t=2439s

I manage to download the connection.zip file from Astra DB and generated admin token keys. But when I try to do connection such as:

   from app.crud import create_entry

I will get this error:

raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'98db9cb2-907a-4f9d-a935-69b69fb2157f-asia-south1.db.astra.datastax.com:29042:611a8370-f129-4099-84e2-c3b2f426ebdc': AuthenticationFailed('Failed to authenticate to 98db9cb2-907a-4f9d-a935-69b69fb2157f-asia-south1.db.astra.datastax.com:29042:611a8370-f129-4099-84e2-c3b2f426ebdc: Error from server: code=0100 [Bad credentials] message="We recently improved your database security. To find out more and reconnect, see https://docs.datastax.com/en/astra/docs/manage-application-tokens.html"'), '98db9cb2-907a-4f9d-a935-69b69fb2157f-asia-south1.db.astra.datastax.com:29042:040ab116-8c77-4eb4-a357-c9bdcbb637d4': AuthenticationFailed('Failed to authenticate to 98db9cb2-907a-4f9d-a935-69b69fb2157f-asia-south1.db.astra.datastax.com:29042:040ab116-8c77-4eb4-a357-c9bdcbb637d4: Error from server: code=0100 [Bad credentials] message="We recently improved your database security. To find out more and reconnect, see https://docs.datastax.com/en/astra/docs/manage-application-tokens.html"'), '98db9cb2-907a-4f9d-a935-69b69fb2157f-asia-south1.db.astra.datastax.com:29042:536e6e99-ef4e-47d0-9308-b0c6cdf4aa37': AuthenticationFailed('Failed to authenticate to 98db9cb2-907a-4f9d-a935-69b69fb2157f-asia-south1.db.astra.datastax.com:29042:536e6e99-ef4e-47d0-9308-b0c6cdf4aa37: Error from server: code=0100 [Bad credentials] message="We recently improved your database security. To find out more and reconnect, see https://docs.datastax.com/en/astra/docs/manage-application-tokens.html"')})

Here is my db.py:

import os
import pathlib
from dotenv import load_dotenv
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from cassandra.cqlengine.connection import register_connection, set_default_connection


BASE_DIR = pathlib.Path(__file__).parent
CLUSTER_BUNDLE = BASE_DIR / 'ignored'/ 'connect.zip'

load_dotenv()

astra_db_client_id = os.environ.get('ASTRA_DB_CLIENT_ID')
astra_db_client_secret = os.environ.get('ASTRA_DB_CLIENT_SECRET')

def get_cluster():
    cloud_config= {
            'secure_connect_bundle': CLUSTER_BUNDLE
    }
    auth_provider = PlainTextAuthProvider(astra_db_client_id, astra_db_client_secret)
    cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider, control_connection_timeout=30,
connect_timeout=30)
    return cluster


def get_session():
    cluster = get_cluster()
    session = cluster.connect()
    register_connection(str(session), session=session)
    set_default_connection(str(session))
    return session

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

I tried to recreate the token key many times and re download the drivers as well but I still have no luck in passing the bad credential errors here:

my crud.py

from .db import get_session
from .models import Product
from cassandra.cqlengine.management import sync_table

session = get_session()
sync_table(Product)


def create_entry(data:dict):
    return Product.create(**data)

models.py

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model


class Product(Model): # -> table
    __keyspace__ = "testing" #
    asin = columns.Text(primary_key=True, required=True)
    title = columns.Text()
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
user1897151
  • 493
  • 2
  • 9
  • 28

1 Answers1

1

You might want to take a look at this

https://docs.datastax.com/en/astra/docs/docs/using-the-datastax-python-driver-to-connect-to-your-database.html

Specifically the section here:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

cloud_config= {
        'secure_connect_bundle': '/path/to/secure-connect-database_name.zip'
}
auth_provider = PlainTextAuthProvider('username', 'password')
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()

When creating the connection you’ll want to pass the secure connect bundle zip. You’ll then provide the clientId and clientSecret as the username and password from the connections file you downloaded.

dwettlaufer
  • 378
  • 1
  • 5