我正在尝试从python(2.7)获取firebase上的数据。
以下是我的规则(在firebseio.com上):
{
"rules": {
"user": {
"$uid": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid"
}
}
}
}
以下是我的数据库截图:
最后,我的python代码:
from firebase import firebase
from firebase.firebase import FirebaseApplication, FirebaseAuthentication
DSN = 'https://<my name>.localhost'
EMAIL = 'qqq@qqq.qqq'
authentication = FirebaseAuthentication(EMAIL, True, True, extra={'id': '<the user id>'})
firebase = FirebaseApplication(DSN, authentication)
firebase.authentication = authentication
print authentication.extra
user = authentication.get_user()
print user.firebase_auth_token
现在我不知道如何获取数据,以及如何向firebase发送数据。
我试图使用行:result = firebase.get('/users', None, {'print': 'pretty'})
,但它给出了这个错误:
ConnectionError: HTTPSConnectionPool(host='<my name>.localhost', port=443): Max retries exceeded with url: /users/.json?print=pretty&auth=<the token code of the user> (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x02A913B0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))
有人能给我一个工作代码吗?
提前谢谢你
兹维卡普
下面是我们为使身份验证工作而采取的步骤。
(1)首先你需要一个Firebase秘密。 在Firebase中创建项目后,单击“设置”。然后单击“数据库”并选择创建机密。
复制你的秘密。稍后它将进入您的代码。
(2)您需要您的firebase URL。 它的格式如下:https://.firebaseio.com 也复制这个。
(3)为Python获取Firebase REST API。 我们用了这个:https://github.com/benletchford/python-firebase-gae 导航到lib目录上方并运行此命令,将firebase代码放入lib目录:
(4)在您的“main.py”文件(或您正在使用的任何文件)中添加以下代码:
(5)将此代码添加到主处理程序(假设您正在使用AppEngine):
现在,当您导航到您的Firebase实时数据库时,您应该可以看到Harry Potter作为用户和其他用户的条目。
相关问题 更多 >
编程相关推荐