【发布时间】: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 "main", 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