2

I'm trying to use Firebase to authenticate users with Python. This is my code:

import pyrebase
import os
firebaseConfig = { #Redacted for Privacy
              'apiKey': "",
              'authDomain': "",
              'databaseURL': "",
              'projectId': "",
              'storageBucket': "",
              'messagingSenderId': "",
              'appId': "",
              'measurementId': ""}
def login():
   print("Username:")
   username = input(">")
   os.system("cls")
   print("Password:")
   password = input(">")
   os.system("cls")

try:
    print(username+" "password)
    login = auth.sign_in_with_email_and_password(username, password)
    print("Successfully logged in!")
    # print(auth.get_account_info(login['idToken']))
    # email = auth.get_account_info(login['idToken'])['users'][0]['email']
    # print(email)
except:
    print("Invalid email or password")
#return

print("successfully logged in again")
sleep(4300)

It keeps thinking it is an invalid email or password, however, it's not.

What can I do to fix this, and have users successfully get logged in?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Etienne
  • 41
  • 2
  • 1
    I would suggest removing the `try`/`except` block to see exactly what's the exception being raised – aaossa Mar 20 '22 at 20:34
  • Please provide additional details such as the error code. – Tim Chiang Mar 21 '22 at 02:31
  • @Etienne have you properly initialized your firebase auth? I have not seen the initialization on your given code. It should be like this. `firebase = pyrebase.initialize_app(firebaseConfig)` and `auth = firebase.auth()` – Marc Anthony B Mar 21 '22 at 04:31
  • Welcome to SO! Please see "[ask]", "[Stack Overflow question checklist](https://meta.stackoverflow.com/questions/260648)" and "[mre]" and all their linked pages. The question as asked is a good start, but we need to know what errors or debugging information you have. Edit your question, and add that information, entering it as if it'd been there originally, without using "Edited" or "Updated" tags as we can tell what changed and when if we need to know. – the Tin Man Mar 21 '22 at 21:07

0 Answers0