web-dev-qa-db-ja.com

Firebaseストレージアップロードファイル-python

python 3.6を使用してファイルをfirebase storageにアップロードするためにいくつかの助けが必要ですが、妥当な結果が得られませんでした。

import firebase_admin
from firebase_admin import credentials, firestore, storage

cred=credentials.Certificate('C:\\Users\\blackturtle\\Envs\\tube\\ps.json')
firebase_admin.initialize_app(cred, {
    'storageBucket': 'gs://dene-2ac17.appspot.com'
})
db = firestore.client()
bucket = storage.bucket()
blob = bucket.blob('hello.txt')
outfile='C:\\Users\\blackturtle\\Envs\\tube\\hello.txt'
blob.upload_from_filename(outfile)

そのコードはこのエラーを下に与えます

Exception has occurred: google.api_core.exceptions.NotFound
404 POST https://www.googleapis.com/upload/storage/v1/b/gs://dene-2ac17.appspot.com/o?uploadType=multipart: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>)
  File "C:\Users\blackturtle\Envs\tube\drive.py", line 27, in <module>
    blob.upload_from_filename(outfile)

以下のコードを変更してファイルをアップロードする場合

import firebase_admin
from firebase_admin import credentials, firestore, storage

cred=credentials.Certificate('C:\\Users\\blackturtle\\Envs\\tube\\ps.json')
firebase_admin.initialize_app(cred, {
    'storageBucket': 'gs://dene-2ac17.appspot.com'
})
db = firestore.client()
bucket = storage.bucket()
blob = bucket.blob('hello.txt')
outfile='C:\\Users\\blackturtle\\Envs\\tube\\hello.txt'
with open(outfile, 'rb') as my_file:
    blob.upload_from_file(my_file)

このエラーが発生しました

Exception has occurred: google.api_core.exceptions.NotFound
404 POST https://www.googleapis.com/upload/storage/v1/b/gs://dene-2ac17.appspot.com/o?uploadType=resumable: ('Response headers must contain header', 'location')
  File "C:\Users\blackturtle\Envs\tube\drive.py", line 29, in <module>
    blob.upload_from_file(my_file)

何が起こっているのでしょうか?

前もって感謝します

5
digging

説明されているように'gs://dene-2ac17.appspot.com''dene-2ac17.appspot.com'に変更してみてください ここ

デフォルトのバケットを使用します

Admin SDKを初期化するときに、デフォルトのバケット名を指定できます。次に、このバケットへの認証済み参照を取得できます。バケット名には、gs://または他のプロトコルプレフィックスを含めないでください。たとえば、Firebaseコンソールに表示されるバケットのURLがgs://bucket-name.appspot.comの場合、文字列bucket-name.appspot.comをAdmin SDKに渡します。

1
Cheche