简体   繁体   English

(401)未经授权使用python-firebase

[英](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: 我正在尝试使用python-firebase库更新Firebase,但使用改编的示例代码无法使身份验证工作:

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. 我一直得到(401)未经授权,但我注意到库生成的令牌与JavaScript版本的FirebaseTokenGenerator生成的令牌完全不同 - 后者在我提供相同的URL,uid和秘密时验证正常。

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. 我注意到一个GitHub问题 ,质疑为什么库不只是使用官方的Python firebase-token-generator ,所以我分叉并实现了建议的更改,以防它会产生影响,但仍然得到相同的结果。

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. 这个图书馆已有4年的历史,这意味着在收购Google之后,很多事情都已经改变了。 The part of how you access Firebase is completely different. 您访问Firebase的部分方式完全不同。

I will recommend to use the official Firebase Admin Python SDK https://github.com/firebase/firebase-admin-python 我建议使用官方的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 https://github.com/thisbejim/Pyrebase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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