1

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?

1
  • 1
    Add a key-value to your firebaseConfig with key=databaseURL and value=your_database_url. see this example. Jan 24, 2021 at 17:02

4 Answers 4

8

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.

0
4

Add

"databaseURL" : ""

in firebaseConfig (if you are not using database).

0

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

0
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;
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.