GCP:在本地计算机中使用服务帐户下载Blob对象

时间:2018-03-01 11:00:26

标签: python cloud

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/service_account.json"

def download_blob(bucket_name, source_blob_name,destination_file_name):
    from google.cloud import storage
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name)
    print('Blob {} downloaded to {}.'.format(source_blob_name,destination_file_name))
  

错误:引发exceptions.from_http_response(响应)   google.api_core.exceptions.Forbidden:403 GET   https://www.googleapis.com/storage/v1/b/test_role?projection=noAcl:    nameofserviceaccount @ projectid .iam.gserviceaccount.com没有storage.buckets.get访问 bucketname

服务帐户已获得项目所有者的许可。

0 个答案:

没有答案