I'm writing a a pub sub function on Google Cloud (cloud functions inline editor) that will trigger every half hour and it uses firestore. For some reason, the function will trigger fine the first time it runs, but after that the following error keeps popping up:
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.
I've had this error before when I used two apps, but this function is ONLY USING one firebase app. Here is the portion of my code where I suspect this is the problem:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
def hello_pubsub(event, context):
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
fire = {<My firebase credentials>}
cred = credentials.Certificate(fire)
default_app = firebase_admin.initialize_app(cred)
db = firestore.client()
........
I figured that the problem is exactly what the error says, I haven't declared the name for the app, so I tried this(along with the other attempt):
default_app = firebase_admin.initialize_app(cred,'App')
# other attempt
default_app = firebase_admin.initialize_app()
And this still does not work. Again, this works the first time the function is triggered, but after that it continually crashes.
Any suggestions?
Thanks for the help!