Google cloud storage 为什么我在尝试访问我的google cloud bucket时会出现403错误?

Google cloud storage 为什么我在尝试访问我的google cloud bucket时会出现403错误?,google-cloud-storage,Google Cloud Storage,我在url上有一个bucket,类似于: 然后我创建了一个名为“api required”的项目,这样我就可以在/api/credentials?project=api required生成凭据 然后,我使用/api/credentials/上的new\u credentials按钮生成了一个json服务帐户密钥。我将下载的json对象保存到一个文件中,并将环境变量GOOGLE\u APPLICATION\u CREDENTIALS指向该文件 现在,我正在用python构建一个应用程序。此代码:

我在url上有一个bucket,类似于:

然后我创建了一个名为“api required”的项目,这样我就可以在/api/credentials?project=api required生成凭据

然后,我使用
/api/credentials/
上的
new\u credentials
按钮生成了一个json服务帐户密钥。我将下载的json对象保存到一个文件中,并将环境变量
GOOGLE\u APPLICATION\u CREDENTIALS
指向该文件

现在,我正在用python构建一个应用程序。此代码:

from gcloud import storage

gcs = storage.Client(project='my client n')
bucket = gcs.get_bucket(bucket_name)
给我一个
403禁止
错误

谷歌云存储JSON API
位于API管理器中启用的API列表中。这似乎涵盖了文档中的所有内容

我一直在翻文件,一辈子都搞不清楚自己做错了什么。如果您能帮我解决这个问题,我们将不胜感激,谢谢

编辑:
以下是回溯:

/Users/asdf/.virtualenvs/analytics_pipeline/lib/python2.7/site-packages/gcloud/storage/client.pyc in get_bucket(self, bucket_name)
    165         """
    166         bucket = Bucket(self, name=bucket_name)
--> 167         bucket.reload(client=self)
    168         return bucket
    169 

/Users/asdf/.virtualenvs/analytics_pipeline/lib/python2.7/site-packages/gcloud/storage/_helpers.pyc in reload(self, client)
     75         api_response = client.connection.api_request(
     76             method='GET', path=self.path, query_params=query_params,
---> 77             _target_object=self)
     78         self._set_properties(api_response)
     79 

/Users/asdf/.virtualenvs/analytics_pipeline/lib/python2.7/site-packages/gcloud/connection.pyc in api_request(self, method, path, query_params, data, content_type, api_base_url, api_version, expect_json, _target_object)
    335         if not 200 <= response.status < 300:
    336             raise make_exception(response, content,
--> 337                                  error_info=method + ' ' + url)
    338 
    339         string_or_bytes = (six.binary_type, six.text_type)
get_bucket(self,bucket_name)中的
/Users/asdf/.virtualenvs/analytics_pipeline/lib/python2.7/site-packages/gcloud/storage/client.pyc
165         """
166 bucket=bucket(self,name=bucket\u name)
-->167铲斗。重新加载(客户机=自身)
168返回铲斗
169
/用户/asdf/.virtualenvs/analytics_pipeline/lib/python2.7/site-packages/gcloud/storage//u helpers.pyc正在重新加载(self,client)
75 api_响应=client.connection.api_请求(
76 method='GET',path=self.path,query_params=query_params,
--->77(目标对象=自身)
78自我设置属性(api响应)
79
/api_请求中的Users/asdf/.virtualenvs/analytics_pipeline/lib/python2.7/site-packages/gcloud/connection.pyc(self、方法、路径、查询参数、数据、内容类型、api_base_url、api_版本、expect_json、_target_对象)
335如果不是200 337错误信息=方法+“”+url)
338
339字符串或字节=(6.binary类型,6.text类型)

因此,我所属的google组可以访问该bucket,而该bucket是由DFP创建的,因为该bucket中充满了DFP数据传输文件/报告。要访问他们的bucket,我必须添加我下载到google组的json文件中的电子邮件(使用添加成员直接按钮,而不是邀请按钮)。一旦我将它们添加到google组中,一切都很顺利。

您的bucket上有什么权限?您的服务帐户是否具有对bucket的读取权限?目前,我已授予每个服务帐户所有者权限。是否可能您没有正确设置环境变量,并且请求是匿名进行的?Try显式指定服务帐户,如下所示:
gcs=Client.from_service_account_json('/path/to/keyfile.json'))
我很确定我指向的是正确的目录,因为如果我更改路径,我会得到一个
没有这样的文件
目录
。至于你的建议,当我这样设置
gcs`时,我不知道如何获取一个bucket,或者下一步该怎么做;
gcs
客户端没有
get\u bucket
方法,我看到了
gcs.connection.credentials.client\u id
None
,这似乎不正确。我想我漏掉了项目编号。
client=storage.client.from\u service\u account\u json('/path/to/file',projectNumber);client.get\u bucket()
应该可以工作。不是吗?