我正在尝试从Firebase Storage下载文件,但是当我使用函数donwload_to_filename或download_as_string时,出现错误。我的代码如下:
具有功能download_to_filename
client = storage2.Client()
buckets = client.list_buckets()
for bucket in buckets:
print(bucket.name)
bucket = client.get_bucket('tmjback.appspot.com')
#blobs = list(bucket.list_blobs())
list_of_blobs = list(bucket.list_blobs(prefix="informe/ordenes/14731d14000000/124b399e000000"))
print(len(list_of_blobs))
path_to_file = str(BASE_DIR) + "test" + ".txt"
file = open(path_to_file,'w+')
file.write("")
file.close()
Blob.download_to_filename(path_to_file)
我收到此错误
TypeError: download_to_filename() missing 1 required positional argument: 'filename'
所以我这样尝试:
Blob.download_to_filename(filename=path_to_file)
但是我得到这个错误
TypeError: download_to_filename() missing 1 required positional argument: 'self'
具有功能download_as_string
client = storage2.Client()
buckets = client.list_buckets()
for bucket in buckets:
print(bucket.name)
bucket = client.get_bucket('tmjback.appspot.com')
#blobs = list(bucket.list_blobs())
list_of_blobs = list(bucket.list_blobs(prefix="path/to/folder"))
print(len(list_of_blobs))
blob = Blob.from_string("gs://path/to/folder")
file = blob.download_as_string(client=client)
file = file.loads(file)
错误
google.api_core.exceptions.Forbidden: 403 GET https://storage.googleapis.com/download/storage/v1/b/informe/o/ordenes%2F14731d14000000%2F124b399e000000%2F201908.json?alt=media: ('Request failed with status code',403,'Expected one of',<HTTPStatus.OK: 200>,<HTTPStatus.PARTIAL_CONTENT: 206>)
我正在使用拥有所有者权限的用户的凭据 我在做什么错了?