question

Leo_mama avatar image
Leo_mama asked Erick Ramirez answered

Connection to Astra DB with Python driver returns "No such file or directory: '../secrets/tmp4e1m0rst/config.json'"

Hello, I followed all the directions from here https://docs.datastax.com/en/astra/docs/connect/drivers/connect-python.html

When I run connect_database.py on Intel Mac (I have not verified on windows machines as I do not have one). I get the following error:

Traceback (most recent call last):
 File "connect_database.py", line 8, in <module>
 cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
 File "cassandra/cluster.py", line 1125, in cassandra.cluster.Cluster.__init__
 File "/Users/sdravida/anaconda3/lib/python3.6/site-packages/cassandra/datastax/cloud/__init__.py", line 88, in get_cloud_config
 config = read_cloud_config_from_zip(cloud_config, create_pyopenssl_context)
 File "/Users/sdravida/anaconda3/lib/python3.6/site-packages/cassandra/datastax/cloud/__init__.py", line 106, in read_cloud_config_from_zip
 return parse_cloud_config(os.path.join(tmp_dir, 'config.json'), cloud_config, create_pyopenssl_context)
 File "/Users/sdravida/anaconda3/lib/python3.6/site-packages/cassandra/datastax/cloud/__init__.py", line 112, in parse_cloud_config
 with open(path, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '../secrets/tmpwkp25acm/config.json'
astra dbpython driver
2 comments
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I was able to get it to work by making the following change the following line

return parse_cloud_config(os.path.join(tmp_dir, 'config.json'), cloud_config, create_pyopenssl_context)

to

return parse_cloud_config(os.path.join(tmp_dir, '<foldername>/config.json'), cloud_config, create_pyopenssl_context)

On Macs, it seems that the uncompressed files are stored inside a home folder. under temp_dir. Can any of the contributors make this change for Macs?

1 Like 1 ·

Great, glad that's working. You'll need to log a ticket with DataStax Support and have them create a Jira for a code change.

0 Likes 0 ·
steve.lacerda avatar image
steve.lacerda answered Erick Ramirez converted comment to answer

Without seeing your code it's hard to tell what's happening. However, that's simply a file not found error, so there are two things that I would check:

1) Are the permissions on that file and the directory above correct. Are they accessible by the application user?

2) Try using an absolute path and not a relative path for your config.json file.

3 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I tried full path and it does not work either. I think the programatic. unzipping and loading to temporary file does not seem to work in my code. Could it be due permissions issues on temp files?

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

cloud_config= {
    'secure_connect_bundle': '<fullpath>/secure-connect-tickers.zip'
}
auth_provider = PlainTextAuthProvider(<ID>, <ID>)
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.")
0 Likes 0 ·
with open(path, 'r') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '<fullpath>/secrets/tmpphzd98x_/config.json'
0 Likes 0 ·

The location of that config.json seems to be in tmp_dir:

return parse_cloud_config(os.path.join(tmp_dir, 'config.json'), cloud_config, create_pyopenssl_context)

so yes, that looks to be in regards to wherever tmp_dir is pointing to.

0 Likes 0 ·
Erick Ramirez avatar image
Erick Ramirez answered

I have to admit, this is the first time someone has reported this issue. I'm also using a 2019 Intel Macbook Pro and I'm not able to replicate the problem you're running into.

Here are the steps I ran in a Python virtual environment:

$ pwd
/Users/erick
$ mkdir test-astra-python
$ cd test-astra-python
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ python -m pip install cassandra-driver
(venv) $ python -c 'import cassandra; print (cassandra.__version__)'
3.25.0

Then I created the test app as specified in that doc you linked and ran it:

(venv) $ python ./connect_database.py
4.0.0.6816

This indicates to me there's an environmental issue that's specific to your machine that you need to look into and it's not a problem with the Python driver. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.