pythonfirebase-storagepyrebase

Python Pyrebase Config


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?


Solution

  • 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.