我需要一些帮助,我正在使用 python 3.6 将文件上传到 firebase 存储,但我无法得到合理的结果。
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)
Run Code Online (Sandbox Code Playgroud)
该代码在下面给出了这个错误
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)
Run Code Online (Sandbox Code Playgroud)
当我更改并使用下面的代码上传文件时
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 = …
Run Code Online (Sandbox Code Playgroud)