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?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
kickass213
  • 51
  • 1
  • 2
  • 7
  • 1
    Add a key-value to your `firebaseConfig` with `key=databaseURL` and `value=your_database_url`. see [this](https://dev.to/gogamic/introduction-to-pyrebase-database-2mif) example. – Behzad Shayegh Jan 24 '21 at 17:02

4 Answers4

7

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
4

Add

"databaseURL" : ""

in firebaseConfig (if you are not using database).

Ibad Shah
  • 439
  • 4
  • 6
0

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

Meqdad Dev
  • 131
  • 1
  • 2
  • 10
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;
    }
  }
}
Gaurav Nagar
  • 191
  • 2
  • 4