Home > Mobile >  firebase connect to database throwing invalid Database URL
firebase connect to database throwing invalid Database URL

Time:11-22

I have a simply python app and I am trying to connect to Firebase, I downloaded my cert.json file and have a valid certificate that authenticates however when I try to create a reference to the database as according to the docs, it throws the following error:

File "C:\Python3\lib\site-packages\firebase_admin\db.py", line 69, in reference client = service.get_client(url) File "C:\Python3\lib\site-packages\firebase_admin\db.py", line 798, in get_client raise ValueError( ValueError: Invalid database URL: "None". Database URL must be a non-empty URL string.

I have added my code below:

import firebase_admin
import os
from firebase_admin import db
from firebase_admin import credentials

certfile = "firebase_cert.json"

credentials = credentials.Certificate(certfile)
database = firebase_admin.initialize_app(credentials)

ref = db.reference("/")
print(ref)

thanks in advance!

CodePudding user response:

As the Firebase documentation for initializing the Admin SDK in Python shows, you will need to specify the URL for your document in your application code:

# Fetch the service account key JSON file contents
cred = credentials.Certificate('path/to/serviceAccountKey.json')

# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://databaseName.firebaseio.com' //            
  • Related