提交了类似的问题,但没有一个解决方案有效。
尝试做 this tutorial 时从谷歌云文档,我在尝试访问数据存储时收到以下错误:
google.api_core.exceptions.Forbidden: 403 Missing or insufficient
permissions.
可以找到执行的文件here .
我确实执行了以下命令:
gcloud auth application-default login
export GOOGLE_APPLICATION_CREDENTIALS="file.json"
请注意,我是在本地计算机上执行该文件。目标是直接从 Google Engine 应用程序对数据存储执行读/写操作。
请您参考如下方法:
从本地计算机运行教程时,我也遇到了同样的错误消息。我使用的是服务帐户(而不是“gcloud auth application-default login”),因为这是 Google 教程中推荐的首选方法。
然而,经过大量调查后,我发现问题是由于 Google 文档中的一个错误而发生的(似乎该文档不是最新的)。
Setting up authentication To run the client library, you must first set up authentication by creating a service account and setting an environment variable. Complete the following steps to set up authentication. For more information, see the GCP authentication documentation .
GCP CONSOLECOMMAND LINE In the GCP Console, go to the Create service account key page.
- GO TO THE CREATE SERVICE ACCOUNT KEY PAGE
- From the Service account drop-down list, select New service account.
- In the Service account name field, enter a name . 4. From the Role drop-down list, select Project > Owner.
文档中的错误与说明的第 4 步有关。在 GCP 控制台的当前实现中,不能直接从服务帐户 key 页面设置角色。相反,您必须转到“IAM & admin”页面来设置“所有者”角色:
In your Google Cloud console select “IAM & admin”->”IAM”
You will see the “ADD” option. This will allow you to set permissions for your new Service Account. Click “ADD”.
You can then enter the service account and role ('Owner' if you are following the instructions in the tutorial).
以下文章“为 Google BigQuery 设置 Google 云服务帐户的缺失指南”提供了更多信息。本文是在 BigQuery 的上下文中编写的,但它同样适用于 Google Datastore:
