1

我在 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 请求的身份验证范围不足”。这是完整的错误跟踪:

回溯(最后一次调用):文件“/usr/lib/python2.7/runpy.py”,第 162 行,在 _run_module_as_main“ main ”中", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/root/.local/lib/python2.7/site-packages /trainer/train.py”,第 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 行,在提交中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)禁止:403 请求的身份验证范围不足。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 中引发 make_exception(headers, error_status .message, use_json=False) 禁止:403 请求的身份验证范围不足。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 中引发 make_exception(headers, error_status .message, use_json=False) 禁止:403 请求的身份验证范围不足。在 _request raise make_exception(headers, error_status.message, use_json=False) Forbidden: 403 Request has enough authentication scopes.在 _request raise make_exception(headers, error_status.message, use_json=False) Forbidden: 403 Request has enough authentication scopes.

我是否需要在某处授予 ML 引擎访问 Datastore 的访问权限?

4

1 回答 1

3

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

于 2017-05-13T21:00:12.943 回答