我已经设置了一个Firebase帐户和一个数据库。
我已经将带有API密钥的配置复制到我的Python代码中。
我在Python 3.5上仍然收到401权限被拒绝的错误
import pyrebase
config = {
"apiKey": "*****",
"authDomain": "***-bot.firebaseapp.com",
"databaseURL": "https://***-bot.firebaseio.com",
"storageBucket": "ebo-bot.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
data = {"name": "Mortimer 'Morty' Smith"}
db.child("users").child("Morty").set(data)我的数据库规则设置为:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}发布于 2016-12-21 08:31:45
我在尝试将数据上传到数据库时也遇到了同样的问题。我重读了https://github.com/thisbejim/Pyrebase/blob/master/README.md的开头部分:
import pyrebase
config = {
"apiKey": "apiKey",
"authDomain": "projectId.firebaseapp.com",
"databaseURL": "https://databaseName.firebaseio.com",
"storageBucket": "projectId.appspot.com",
"serviceAccount": "path/to/serviceAccountCredentials.json"
}
firebase = pyrebase.initialize_app(config)将serviceAccount条目添加到配置中,其中包含您可以从Firebase下载的密钥的路径。

为此:设置>项目设置>服务帐户>生成新私钥。
将该密钥放在某个所需的位置,并将该位置放在"serviceAccount“路径中。
希望能有所帮助。
发布于 2018-07-12 02:52:26
set方法缺少用户“‘idToken”,并且您忘记进行身份验证,请尝试:
import pyrebase
config = {
"apiKey": "*****",
"authDomain": "***-bot.firebaseapp.com",
"databaseURL": "https://***-bot.firebaseio.com",
"storageBucket": "ebo-bot.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
auth = firebase.auth()
user = auth.sign_in_with_email_and_password("usernamehere@user.com", "passwordhere")
data = {"name": "Mortimer 'Morty' Smith"}
db.child("users").child("Morty").set(data,user['idToken'])(在运行此命令之前,您还需要创建一个用户,请转到firebase仪表板并单击身份验证选项卡,您可以在那里添加用户)
https://stackoverflow.com/questions/41082171
复制相似问题