0

我在Google ML引擎上運行TensorFlow模型。模型訓練完成後,我想將結果存儲到數據存儲的JSON字符串中。對於這一點,我使用了以下內容:Google ML引擎和Python數據存儲API,'Forbidden:403請求的認證範圍不足。'

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 「主要」,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」,在 FLAGS.entity_type線243, )文件 「/root/.local/lib/python2.7/site-packages/trainer/data_helpers.py」, 線253,在put_json_into_datastore datastore_client。放(實體)文件「/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 「, line 355,in 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​​」, line 243,in _commit self.project,self._commit_request,self._id)File「/ 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請求沒有足夠的認證 作用域。

我是否需要授予ML引擎訪問Datastore的權限?

+0

愚蠢的問題,但只是確保...是在同一個項目內的數據存儲和雲ML引擎工作? –

+0

@ T.Okahara yap,同一個項目。儘管無法訪問數據存儲,但我可以通過ML引擎將文件保存到存儲。 –

回答

2

Cloud ML服務沒有以足夠訪問數據存儲的權限執行。解決這個問題的一個方法是上傳具有對雲數據存儲訪問權限的服務帳戶的憑證(例如,json服務帳戶密鑰文件)。然後,您可以使用它來獲取能夠訪問數據存儲的憑證。

相關問題