Firebase实时数据库与存储问题Python

rhfm7lfc  于 2022-12-25  发布在  Python
关注(0)|答案(1)|浏览(135)

我同时使用Firebase实时数据库和Firebase存储,但默认应用程序出现问题。存储命令转到默认应用程序(数据库应用程序),但未找到所需数据。

!pip install pygsheets
import pygsheets
import pandas as pd
from datetime import datetime
import pytz
from pydrive.auth import GoogleAuth
from google.colab import drive
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
from firebase_admin import credentials, initialize_app, storage, db
import matplotlib.pyplot as plt

cred = credentials.Certificate('key.json')
database = initialize_app(cred, {'databaseURL': "https://project-147196781260390231-default-rtdb.europe-west1.firebasedatabase.app/"})
imgStorage = initialize_app(cred, {'storageBucket': 'project-147196781260390231.appspot.com'}, name = 'bucket')

dt = datetime.now(cairoTz)
y = dt.year
M = dt.month
d = dt.day
h = dt.hour
m = dt.minute
s = dt.second

lhour = df.loc\[(df\['Hour'\] == h) | ((df\['Hour'\] ==  h - 1) & (df\['Minute'\] \>= m))\]
lday = df.loc\[(df\['Day'\] == d)| ((df\['Day'\] ==  d - 1) & (df\['Hour'\] \>= h))\]
lall = df

tempHplt = plt.figure(figsize=(10, 3))
tempHplt_name = 'tempHplt.png'
xTemph = lhour\['Minute'\].astype(int).astype(str)
yTemph = lhour\['Temperature'\]
plt.plot(xTemph, yTemph)
plt.savefig('tempHplt.png')
file_path = tempHplt_name
bucket = storage.bucket() # storage bucket
blob = bucket.blob(file_path)
blob.upload_from_filename(file_path)

我尝试将初始化应用程序放在一个变量中并从中调用存储函数,但给出了一个错误。
属性错误:"App"对象没有属性"storage"
如果不使用变量,则错误如下:
ValueError:未指定存储桶名称,初始化App时通过"storageBucket"选项指定存储桶名称,或调用storage.bucket()函数时显式指定存储桶名称。

fnvucqvd

fnvucqvd1#

好的,解决方案是指定应用程序

bucket = storage.bucket(imgStorage) # storage bucket

相关问题