3

Trust you are doing well. I am new to firebase and trying to do user authentication. I have installed pyrebase4 and created a project on the firebase console. I also enabled sign in with "Email and Password" and trying to connect with my app. Below is my code that I am trying:

    import pyrebase

#connect to firebase via key-value pair
firebaseConfig = {
    "apiKey": "xxxxxxxxxxxxxxxxxx",
    "authDomain": "xxxxxxxxxxx",
    "projectId": "xxxxxxxxxxx",
    "storageBucket": "xxxxxxxxxxxxxx",
    "messagingSenderId": "xxxxxxxxxxxxx",
    "appId": "xxxxxxxxxxxxxxxxxxxx",
    "measurementId": "G-5GCDEC526E"
}

#initialize the app
firebase = pyrebase.initialize_app(firebaseConfig)

#connect to firebase database
#db = firebase.database()
auth = firebase.auth()
#storage = firebase.storage()

#user login authentication
email = input("Enter your email: \n")
password = input("Enter your password: \n")
user = auth.create_user_with_email_and_password(email, password)
auth.get_account_info(user['idToken'])

I am using VS Code as an IDE, Python 3.8, and Ubuntu OS. Below is the error I am getting:

python3 main.py
Traceback (most recent call last):
  File "main.py", line 15, in <module>
    firebase = pyrebase.initialize_app(firebaseConfig)
  File "/home/sonu/.local/lib/python3.8/site-packages/pyrebase/pyrebase.py", line 28, in initialize_app
    return Firebase(config)
  File "/home/sonu/.local/lib/python3.8/site-packages/pyrebase/pyrebase.py", line 36, in __init__
    self.database_url = config["databaseURL"]
KeyError: 'databaseURL'

Can you help me solve the issue? Thanks in advance.

Sonu Kumar
  • 57
  • 1
  • 10

4 Answers4

4

As the error said. The databaseURL property is missing from your configuration.

Since now the Realtime Database is not automatically be created at the time you create the new firebase project so the databaseURL is not included by default. See also

Siratee K.
  • 187
  • 2
  • 12
3

You can add an empty string to the key databaseURL, but be careful when you want to work with Realtime database, you need to update the configurations dictionary in your Python code.

As a result, you can start with these configurations if you don't have or you don't need to work with Realtime database:

firebaseConfig = {
    "apiKey": "xxxxxxxxxxxxxxxxxx",
    "authDomain": "xxxxxxxxxxx",
    "projectId": "xxxxxxxxxxx",
    "storageBucket": "xxxxxxxxxxxxxx",
    "messagingSenderId": "xxxxxxxxxxxxx",
    "appId": "xxxxxxxxxxxxxxxxxxxx",
    "measurementId": "G-5GCDEC526E",
    "databaseURL": ""
}

Or you can start with these configurations if you've already created a Realtime database:

firebaseConfig = {
    "apiKey": "xxxxxxxxxxxxxxxxxx",
    "authDomain": "xxxxxxxxxxx",
    "projectId": "xxxxxxxxxxx",
    "storageBucket": "xxxxxxxxxxxxxx",
    "messagingSenderId": "xxxxxxxxxxxxx",
    "appId": "xxxxxxxxxxxxxxxxxxxx",
    "measurementId": "G-5GCDEC526E",
    "databaseURL": "https://fir-#######-rtdb.europe-##########.app/"
}

You can find your database URL at the top of your database viewer in firebase console. [See the image below]

A screenshot for Realtime database from firebase

Dharman
  • 30,962
  • 25
  • 85
  • 135
Meqdad Dev
  • 131
  • 1
  • 2
  • 10
0

Add databaseURL in your config object ref

avatar
  • 161
  • 1
  • 6
0
firebaseConfig = {
    "apiKey": "xxxxxxxxxxxxxxxxxx",
    "authDomain": "xxxxxxxxxxx",
    "projectId": "xxxxxxxxxxx",
    "storageBucket": "xxxxxxxxxxxxxx",
    "messagingSenderId": "xxxxxxxxxxxxx",
    "appId": "xxxxxxxxxxxxxxxxxxxx",
    "measurementId": "G-5GCDEC526E",
    "databaseURL":"your database url"
}

It is found in the realtime database tab above your saved data.

Nahid Khan
  • 11
  • 2