【问题标题】:Google ML Engine and Python Datastore API, 'Forbidden: 403 Request had insufficient authentication scopes.'Google ML Engine 和 Python Datastore API,“禁止:403 请求的身份验证范围不足。”
【发布时间】:2017-10-12 16:06:57
【问题描述】:

我正在 Google ML Engine 上运行 TensorFlow 模型。模型训练完成后,我想将带有结果的 JSON 字符串存储到 Datastore。为此,我使用以下内容:

from gcloud import datastore

def put_json_into_datastore(json_str, project_id, entity_type):
    """
    Store json string in Datastore
    """
    # Instantiate the client to the project
    datastore_client = datastore.Client(project_id)
    # The name/ID for the new entity
    name = str(datetime.datetime.now())
    # The Cloud Datastore key for the new entity
    entity_key = datastore_client.key(entity_type, name)
    # Prepare the new entity
    entity = datastore.Entity(key=entity_key)
    # Get the json string into the entity
    entity.update(json_str)
    # Put the entity into Datastore
    datastore_client.put(entity)

虽然,我收到错误“禁止:403 请求的身份验证范围不足。”这是完整的错误跟踪:

Traceback(最近一次调用最后一次):文件 “/usr/lib/python2.7/runpy.py”,第 162 行,在 _run_module_as_main "ma​​in", fname, loader, pkg_name) 文件 "/usr/lib/python2.7/runpy.py",第 72 行,在 _run_code run_globals 文件“/root/.local/lib/python2.7/site-packages/trainer/train.py”中的 exec 代码,第 243 行, 在 FLAGS.entity_type)文件“/root/.local/lib/python2.7/site-packages/trainer/data_helpers.py”, 第 253 行,在 put_json_into_datastore 中 datastore_client.put(实体)文件“/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py”, 第 329 行,输入 self.put_multi(entities=[entity]) 文件 "/usr/local/lib/python2.7/dist-packages/gcloud/datastore/client.py", 第 355 行,在 put_multi current.commit() 文件“/usr/local/lib/python2.7/dist-packages/gcloud/datastore/batch.py​​”, 第 260 行,提交中 self._commit() 文件“/usr/local/lib/python2.7/dist-packages/gcloud/datastore/batch.py​​”, 第 243 行,在 _commit self.project,self._commit_request,self._id)文件“/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py”, 第 342 行,提交中 _datastore_pb2.CommitResponse)文件“/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py”, 第 124 行,在 _rpc 中 data=request_pb.SerializeToString()) 文件“/usr/local/lib/python2.7/dist-packages/gcloud/datastore/connection.py”, 第 98 行,在 _request 中 raise make_exception(headers, error_status.message, use_json=False) Forbidden: 403 Request had enough authentication 范围。

我是否需要授予机器学习引擎访问数据存储区的权限?

【问题讨论】:

  • 愚蠢的问题,但只是确保......数据存储和云 ML 引擎工作在同一个项目中吗?
  • @T.Okahara 是的,同一个项目。我可以通过 ML 引擎将文件保存到 Storage,但无法访问 Datastore。

标签: python google-app-engine google-cloud-datastore google-cloud-platform google-cloud-ml-engine


【解决方案1】:

Cloud ML 服务未使用足以访问 Datastore 的权限执行。解决此问题的一种方法是为有权访问 Cloud Datastore 的服务帐户上传凭据(例如 json 服务帐户密钥文件)。然后,您可以使用它来获取能够访问 Datastore 的凭据。

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 2016-04-28
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    相关资源
    最近更新 更多