Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Firebase DB reference error

I need to update certain node in my Firebase DB, so this is what I'm doing:

from firebase_admin import db

def update_data_in_firebase(gid, account_id, location_id, data_to_update):
    firebase_url = 'saved_locations/{}/accounts/{}/locations/{}'.format(gid, account_id, location_id)
    ref = db.reference(path=firebase_url)
    ref.update(data_to_update)

So, the code above is what I'm trying to do to update the data in the Firebase node, but I'm getting this error:

Invalid databaseURL option: "None". databaseURL must be a non-empty URL string.

Of course, I checked out the firebase URL and it matches, so the problem is not the URL, or, I'm missing something with the path, I mean, should I use absolute insted of relative path.

like image 443
Gerardo Ruiz Avatar asked Mar 27 '18 02:03

Gerardo Ruiz


1 Answers

As mentioned in the comments of the question, the databaseURL was not defined.

Answer:

cred = credentials.Certificate('your_config.json')
firebase_admin = firebase_admin.initialize_app(cred, {'databaseURL': 'https://your-firebase-db'})

In the main docs of Firebase, I couldn't find the error on my app initialization: Firebase Admin Docs But in the Realtime Database - Admin (Get Started), there is a snippet where they initialize the Firebase App defining the databaseURL

like image 169
Gerardo Ruiz Avatar answered Oct 05 '22 13:10

Gerardo Ruiz