Python Pyrebase Config

Question:

When I’m trying to run my code:

import pyrebase

    firebaseConfig = {
        "apiKey": "xxxxxx",
        "authDomain": "xxxxxx",
        "projectId": "xxxxxx",
        "storageBucket": "xxxxxxx",
        "serviceAccount": "xxxxxxxxx"
    }
    
    firebase_storage = pyrebase.initialize_app(firebaseConfig)
    storage = firebase_storage.storage()
    
    storage.child("uploads").put("xxxxxxx")

I’m getting an error:

self.database_url = config["databaseURL"]

KeyError: ‘databaseURL’

I don’t know what to do. Can someone help me?

Asked By: kickass213

||

Answers:

When you create a new Firebase project it no longer creates a Realtime Database by default. And that also means that the databaseURL key is no longer included in the configuration snippet by default.

It looks like Pyrebase still requires this key to exist though, which is why you get an error.

Two things to try (in this order):

  1. Just add a key with no value, or a dummy value to the firebaseConfig:

    firebaseConfig = {
        "apiKey": "xxxxxx",
        "authDomain": "xxxxxx",
        "databaseURL": "xxxxxx",
        "projectId": "xxxxxx",
        "storageBucket": "xxxxxxx",
        "serviceAccount": "xxxxxxxxx"
    }
    
  2. If the above doesn’t work, you can create a Realtime Database in the Firebase console, and get the new config snippet from there.

I also filed an issue against Pyrebase to no longer require this key, which is what all official Firebase SDKs have been updated to do.

Answered By: Frank van Puffelen

Add

"databaseURL" : ""

in firebaseConfig (if you are not using database).

Answered By: Ibad Shah

You need to add databaseURL key to your configurations.
Please take a look at this answer:
KeyError: 'databaseURL' while Firebase Authentication in Python

Answered By: Meqdad Dev
import pyrebase

config ={

    "apiKey": "*********",
    "authDomain": "***-****.firebaseapp.com",
    "projectId": "****-*****",
    "storageBucket": "****-***.appspot.com",
    "messagingSenderId": "********",
    "appId": "1:********:web:*********",
    "measurementId": "G-*********",
    "databaseURL" : ""

}

firebase = pyrebase.initialize_app(config)
storage = firebase.storage()

storage.child("download1.png").put("download.png")

Rules

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}
Answered By: Gaurav Nagar