gpt4 book ai didi

python - HTTP 错误 400 : Bad request to Firebase using Python

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:08 26 4
gpt4 key购买 nike

我正在使用python-firebase library by Ozgur Vatansever对于我的程序。

我以前能够向我的 Firebase 写入/读取数据,但是随着身份验证的引入,我不能了。使用:

from firebase import firebase

auth = firebase.FirebaseAuthentication('MY_FIREBASE_SECRET','myEmail@email.com')
myFirebase = firebase.FirebaseApplication('https://MYFIREBASE.firebaseio.com', auth)

result = myFirebase.get('/users', None)
print result

结果:

HTTPError: 400 Client Error: Bad Request

相反,不使用身份验证:

 myFirebase = firebase.FirebaseApplication('https://MYFIREBASE.firebaseio.com', None)        
result = myFirebase.get('/users', None)

按预期工作。如果我在使用身份验证时收到此 HTTP 错误:400 的任何帮助,我们将不胜感激。

最佳答案

我正在使用该库的 1.2 版本和 python 2.7
here 中有一个关于如何使用身份验证轻松连接的示例。

import datetime

from firebase.firebase import FirebaseApplication, FirebaseAuthentication


if __name__ == '__main__':
SECRET = '12345678901234567890'
DSN = 'https://firebase.localhost'
EMAIL = 'your@email.com'
authentication = FirebaseAuthentication(SECRET,EMAIL, True, True)
firebase = FirebaseApplication(DSN, authentication)

firebase.get('/users', None,
params={'print': 'pretty'},
headers={'X_FANCY_HEADER': 'very fancy'})

data = {'name': 'Ozgur Vatansever', 'age': 26,
'created_at': datetime.datetime.now()}

snapshot = firebase.post('/users', data)
print(snapshot['name'])

def callback_get(response):
with open('/dev/null', 'w') as f:
f.write(response)
firebase.get_async('/users', snapshot['name'], callback=callback_get)

This is a test app so there's no issue with the secret 奥 git _a希望这有帮助!

关于python - HTTP 错误 400 : Bad request to Firebase using Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28731549/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com