Reputation: 73
I am making an app that need access to files in my Google Cloud Buckets. I used this tutorial to get access to my files. The tutorial says you need to use the "service account key page"-json file to get access to the buckets, like this:
storage_client= storage.Client.from_service_account_json("/home/Project/red-freedom-XXXXX-XXXXXXXXX.json")
The Json-file is stored in the same folder as the main.py and the app.yaml files. The program runs smoothly when i run it locally, however when i deploy it, i get:
FileNotFoundError: [Errno 2] No such file or directory: "/home/Project/red-freedom-XXXXX-XXXXXXXXX.json"
How do i fix this problem?
Upvotes: 1
Views: 1365
Reputation: 21520
It looks like you're using an absolute path to the .json
file based on your local filesystem, but on App Engine this needs to be a different path.
Instead, you can use a relative path from the file you're trying to create the client in:
import os
current_directory = os.path.abspath(os.path.dirname(__file__))
path_to_service_account_json = os.path.join(current_directory, 'red-freedom-XXXXX-XXXXXXXXX.json')
storage_client= storage.Client.from_service_account_json(path_to_service_account_json)
Upvotes: 1