Google ML引擎和Python数据存储API';禁止:403请求的身份验证范围不足;

Google ML引擎和Python数据存储API';禁止:403请求的身份验证范围不足;,python,google-app-engine,google-cloud-datastore,google-cloud-platform,google-cloud-ml-engine,Python,Google App Engine,Google Cloud Datastore,Google Cloud Platform,Google Cloud Ml Engine,我正在谷歌ML引擎上运行一个TensorFlow模型。当模型训练完成后,我想将一个JSON字符串和结果存储到数据存储中。为此,我使用以下方法: from gcloud import datastore def put_json_into_datastore(json_str, project_id, entity_type): """ Store json string in Datastore """ # Instantiate the client to t

我正在谷歌ML引擎上运行一个TensorFlow模型。当模型训练完成后,我想将一个JSON字符串和结果存储到数据存储中。为此,我使用以下方法:

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行,在作为主模块的运行模块中 “main”,fname,loader,pkg_name)文件“/usr/lib/python2.7/runpy.py”,第72行,在运行代码中 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行,将\u json\u放入\u数据存储 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行,输入多个 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行,in_commit self.project、self.\u commit\u request、self.\u 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行,in_rpc data=request_pb.SerializeToString()文件“/usr/local/lib/python2.7/dist packages/gcloud/datastore/connection.py”, 第98行,输入请求 禁止引发make_异常(标题,error_status.message,use_json=False):403请求的身份验证不足 范围


我是否需要为ML引擎授予访问数据存储的权限?

云ML服务的执行权限不足以访问数据存储。解决这一问题的一种方法是为能够访问云数据存储的服务帐户上载凭据(例如json服务帐户密钥文件)。然后,您可以使用它来获取能够访问数据存储的凭据。

这是一个愚蠢的问题,但只需确保……数据存储和云ML引擎作业是否在同一个项目中?@T.Okahara yap,同一个项目。我能够通过ML引擎将文件保存到存储中,尽管我无法访问数据存储。