简体   繁体   中英

(401) Unauthorized with python-firebase

I am trying to update Firebase using the python-firebase library, but cannot get authentication to work, using adapted sample code:

from firebase import firebase as fb
auth = fb.FirebaseAuthentication('<firebase secret>', 'me@gmail.com', 
                                 auth_payload={'uid': '<uid>'}) // NB renamed extras -> auth_payload, id -> uid here
firebase = fb.FirebaseApplication('https://<url>.firebaseio.com', authentication=auth)
result = firebase.get('/users', name=None, connection=None, 
                      params={'print': 'pretty'}) // HTTPError: 401 Client Error: Unauthorized
print result 

I keep getting (401) Unauthorized, but I notice that the token generated by the library is radically different to one generated by a JavaScript version of FirebaseTokenGenerator - and the latter authenticates fine when I provide the same URL, uid and secret.

I noticed a GitHub issue , questioning why the library did not just use the official Python firebase-token-generator , so I forked and implemented the suggested change just in case it would make a difference, but still get the same result.

Can anyone suggest what might be tripping me up here?

This library is 4 years old which means lots of things have been changed for firebase especially after Google's acquisition. The part of how you access Firebase is completely different.

I will recommend to use the official Firebase Admin Python SDK https://github.com/firebase/firebase-admin-python

A really good alternative but prefer the official is this:

https://github.com/thisbejim/Pyrebase

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM