【发布时间】:2018-10-05 23:34:11
【问题描述】:
我在谷歌云存储桶中有一个文件夹结构
bucket_name = 'logs'
json_location = '/logs/files/2018/file.json'
我尝试使用此代码在jupyter notebook 中读取此json 文件
from google.cloud import storage
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "logs/files/2018/file.json"
def download_blob(source_blob_name, bucket_name, destination_file_name):
"""Downloads a blob from the bucket."""
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))
然后调用函数
download_blob('file.json', 'logs', 'file.json')
我得到了这个错误
DefaultCredentialsError: File /logs/files/2018/file.json was not found.
我查看了在 stackoverflow 上提出的所有类似问题,但找不到解决方案。
json 文件存在,可以在谷歌云存储的 json_location 中打开或下载。
【问题讨论】:
标签: python-3.x google-cloud-storage