为什么我在 python firebase-admin initialize_app() 上收到此错误?
Why I get this error on python firebase-admin initialize_app()?
当我尝试连接 google firebase 实时数据库时,出现此错误:
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.
这是我的代码:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate('firebase-sdk.json')
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://test-139a6-default-rtdb.firebaseio.com/'
})
您只需初始化(创建)应用程序一次。创建应用程序后,请改用 get_app
:
# The default app's name is "[DEFAULT]"
firebase_admin.get_app(name='[DEFAULT]')
您只需初始化 Admin SDK 一次。您可以使用以下 if 语句检查 Admin SDK 是否已初始化:
if not firebase_admin._apps:
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://test-139a6-default-rtdb.firebaseio.com/'
})
当我尝试连接 google firebase 实时数据库时,出现此错误:
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.
这是我的代码:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate('firebase-sdk.json')
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://test-139a6-default-rtdb.firebaseio.com/'
})
您只需初始化(创建)应用程序一次。创建应用程序后,请改用 get_app
:
# The default app's name is "[DEFAULT]"
firebase_admin.get_app(name='[DEFAULT]')
您只需初始化 Admin SDK 一次。您可以使用以下 if 语句检查 Admin SDK 是否已初始化:
if not firebase_admin._apps:
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://test-139a6-default-rtdb.firebaseio.com/'
})