Home > Software engineering >  Unable to create keyspace with the Python driver, getting Unauthorized error "Missing correct p
Unable to create keyspace with the Python driver, getting Unauthorized error "Missing correct p

Time:10-21

I am trying to create a keyspace on my `Astra' instance but I have gotten this error while trying the execute the CREATE statement:

---------------------------------------------------------------------------
Unauthorized                              Traceback (most recent call last)
/home/ryan/Documents/is3107-2/project/connect-to-db.ipynb Cell 2 in <cell line: 1>()
----> 1 session.execute('''
      2 CREATE KEYSPACE IF NOT EXISTS dblp
      3 WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};
      4 ''')
      6 session.set_keyspace("dblp")

File ~/anaconda3/envs/is3107/lib/python3.9/site-packages/cassandra/cluster.py:2618, in cassandra.cluster.Session.execute()

File ~/anaconda3/envs/is3107/lib/python3.9/site-packages/cassandra/cluster.py:4894, in cassandra.cluster.ResponseFuture.result()

Unauthorized: Error from server: code=2100 [Unauthorized] message="Missing correct permission on dblp."

This error reoccurs when I ran the same CQL statement on Astra CQL console tab.

Here are the codes:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
client_id = .....
secret = ....
cloud_config= {
         'secure_connect_bundle': '/home/ryan/Documents/is3107-2/project/secure-connect-is3107-project-by-ng-guangren-ryan.zip'
}
auth_provider = PlainTextAuthProvider(client_id,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.")
#Returned row[0] with the IP address


session.execute('''
CREATE KEYSPACE IF NOT EXISTS dblp
WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};
''')

session.set_keyspace("dblp")

CodePudding user response:

It is not possible to create a keyspace programatically or via cqlsh with Astra web UI

Alternatively, you can also create a new keyspace using the Astra DevOps API.

For details, see Managing multiple keyspaces in Astra DB. Cheers!

  • Related