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?
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):
-
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"
}
-
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.
Add
"databaseURL" : ""
in firebaseConfig (if you are not using database).
You need to add databaseURL
key to your configurations.
Please take a look at this answer:
KeyError: 'databaseURL' while Firebase Authentication in Python
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;
}
}
}
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?
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):
-
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" }
-
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.
Add
"databaseURL" : ""
in firebaseConfig (if you are not using database).
You need to add databaseURL
key to your configurations.
Please take a look at this answer:
KeyError: 'databaseURL' while Firebase Authentication in Python
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;
}
}
}