0
votes

I need to use python to access files on google cloud storage. I'm using the following code -

from google.cloud import storage
client = storage.Client.from_service_account_json('json/file/path')
bucket = client.get_bucket('demo')

I get the following error -

google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b/iot-demo?projection=noAcl: [email protected] does not have storage.buckets.get access to demo.

Google Storage JSON API is enabled, I have given the 'storageaccess' account the 'Storage Admin' role. I have also tried giving the 'Project Owner' role.

1
Is "demo" the real bucket name? If so are you sure you own it? Common names like that are usually owned by someone else from a long time ago. - Mike Schwartz
I just replaced the real bucket name with "demo" for the purpose of asking the question. The bucket I'm using is owned by me, and I have Storage Admin access to it. - Riaz Moradian

1 Answers

0
votes

I ran into this same issue. My problem was that I created a service account that didn't have sufficient permissions. I deleted the service account and created a new one with the correct permissions. However, I named it the same as the old service account and it seems that GCP was defaulting to the old service account permissions. My solution was to create a new service account with a new name and the right role (Storage Admin) to apply the correct permissions.