Загрузка Blob из Firebase Storage return 403 - PullRequest
3 голосов
/ 07 ноября 2019

Я пытаюсь загрузить файл из 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>)

Я использую учетные данные от пользователя с привилегиями владельца Чтоя делаю не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...