簡體   English   中英

無法從 Google Vault API 導出下載 blob

[英]can't download blob from Google Vault API export

我也無法讓它工作。 在 Google API 示例文檔中,它說明了這一點,見下文。 我能夠使用存儲帳戶進行身份驗證,並訪問存儲桶並查看 blob,但如果我使用任何類型的 blob 方法,例如 blob.exists() 或 blob.download_from_filename(),則會收到禁止的 403 錯誤. 我已向經過身份驗證的用戶帳戶和服務帳戶添加了存儲管理員權限,但仍然出現此錯誤。 下面的文檔沒有提到任何關於使用服務帳戶訪問 blob 的內容。 但是,我不知道如何使用用戶帳戶而不是服務帳戶來實例化存儲客戶端。 有沒有人有這方面的例子?

def download_exports(service, matter_id):
#"""Google Cloud storage service is authenticated by running
#`gcloud auth application-default login` and expects a billing enabled project
#in ENV variable `GOOGLE_CLOUD_PROJECT` """
gcpClient = storage.Client()
matter_id = os.environ['MATTERID']
for export in vaultService.matters().exports().list(
      matterId=matter_id).execute()['exports']:
    if 'cloudStorageSink' in export:
      directory = export['name']
      if not os.path.exists(directory):
       os.makedirs(directory)
      print(export['id'])
  for sinkFile in export['cloudStorageSink']['files']:
    filename = '%s/%s' % (directory, sinkFile['objectName'].split('/')[-1])
    objectURI = 'gs://%s/%s' % (sinkFile['bucketName'],
                                sinkFile['objectName'])
    print('get %s to %s' % (objectURI, filename))
    gcpClient.download_blob_to_file(objectURI, open(filename, 'wb+'))

好的,我發現了問題所在。 我通過使用默認存儲服務帳戶而不是創建新服務帳戶來解決此問題。

    #use the default service account       
    gcpClient = storage.Client()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM