[英]Error accessing google cloud storage through python
I need to use python to access files on google cloud storage. 我需要使用python访问Google云存储上的文件。 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: storageaccess@zeta-bonsai-215512.iam.gserviceaccount.com 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. 启用了Google Storage JSON API,我为“ storageaccess”帐户赋予了“存储管理员”角色。 I have also tried giving the 'Project Owner' role.
我还尝试过赋予“项目负责人”角色。
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.
但是,我将其命名为与旧服务帐户相同,并且似乎GCP默认使用旧服务帐户权限。 My solution was to create a new service account with a new name and the right role (
Storage Admin
) to apply the correct permissions. 我的解决方案是使用新名称和正确的角色(
Storage Admin
)创建一个新的服务帐户,以应用正确的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.