firebase 关闭火座连接

7xllpg7q  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(127)

我有3个python文件链接到一个文件,如下所示:

#chained.py
import file1
import file2
import file3

chained.py中的每个文件都用firebase_admin.initialize_app(cred)方法初始化一个firebase管理对象。当我分别运行这三个文件时,一切都按预期运行。当我运行chained.py时,当第二个文件开始运行时,我得到下面的错误。

File "/home/usern/.local/lib/python3.6/site-packages/firebase_admin/__init__.py", line 72, in initialize_app
    'The default Firebase app already exists. This means you called '
ValueError: The default Firebase app already exists. This means you called initialize_app() more than once without providing an app name as the second argument. In most cases you only need to call initialize_app() once. But if you do want to initialize multiple apps, pass a second argument to initialize_app() to give each app a unique name.

我假设修复方法是在脚本结束时关闭连接,但是我还没有找到解决方法。有没有什么常见的做法来处理这个问题?或者有一种方法来解决这个问题。

gmxoilav

gmxoilav1#

您可以使用以下代码检查Firebase应用程序是否已初始化。

import firebase_admin
from firebase_admin import credentials, initialize_app, storage

FIREBASE_STORAGE_PATH = "firebase_storage_path_here"

if not firebase_admin._apps:
    cred = credentials.Certificate(JSON_FILE)
    initialize_app(cred, {'storageBucket': FIREBASE_STORAGE_PATH})

相关问题