7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flask】【Firebase】 ValueError: The default Firebase app already exists. This means you called initialize_app() ...

Posted at

はじめに

Flaskにてリクエストを投げると題のようなエラーが出た。エラー文の通り、Firebaseの初期化処理で2回目が呼ばれてしまっていることが原因。その解決方法を下記する。

解決方法

以下のように、初期化済みかの判定処理を入れ、初期化されていない場合は初期化を行うようにする。
2回目以降は下記if文がFalseとなり、初期化をスキップする。

import firebase_admin
from firebase_admin import credentials

# 初期化済みかを判定する
if not firebase_admin._apps:
    # 初期済みでない場合は初期化処理を行う
    cred = credentials.Certificate('path/to/serviceAccountKey.json') 
    default_app = firebase_admin.initialize_app(cred)

おわりに

こちらを参考。
https://stackoverflow.com/questions/44293241/check-if-a-firebase-app-is-already-initialized-in-python

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?