thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.06k stars 527 forks source link

Errno 401 Client Error using set() method #306

Closed Nv7-GitHub closed 5 years ago

Nv7-GitHub commented 5 years ago

I am trying to save data using firebase. All my credentials are correct. Code and error below. Code

import pyrebase

pyrebase_config = {
    'apiKey': "apiKey",
    'authDomain': "projectname.firebaseapp.com",
    'databaseURL': "https://projectname.firebaseio.com",
    'projectId': "projectname",
    'storageBucket': "projectname.appspot.com",
    'messagingSenderId': "messageSenderId",
    'appId': "appId",
    'serviceAccount': 'serviceaccount.json'
}
firebase = pyrebase.initialize_app(pyrebase_config)
auth = firebase.auth()
db = firebase.database()
save = auth.sign_in_with_email_and_password('junk4Nv7@gmail.com', 'abcdefg')

chats = []
accounts = []

db.child('chats').set(chats, token=save['idToken'])
db.child('accounts').set(accounts, token=save['idToken'])

Error

Traceback (most recent call last):
  File "Directory", line 444, in raise_detailed_error
    request_object.raise_for_status()
  File "Directory", line 862, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://areallylongURL
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/nishant/Documents/Python/Chat/setup.py", line 21, in <module>
    db.child('chats').set(chats, token=save['idToken'])
  File "/Users/nishant/Chat/lib/python3.7/site-packages/pyrebase/pyrebase.py", line 301, in set
    raise_detailed_error(request_object)
  File "/Users/nishant/Chat/lib/python3.7/site-packages/pyrebase/pyrebase.py", line 448, in raise_detailed_error
    raise HTTPError(e, request_object.text)
requests.exceptions.HTTPError: [Errno 401 Client Error: Unauthorized for url: https://areallylongURL] {
  "error" : "Permission denied"
}
hbg commented 5 years ago

Have you enabled email sign-in with Firebase?

If so, make sure your read/write rules are in testing mode and then see if it works

Nv7-GitHub commented 5 years ago

The answer was to switch to real-time database