使用Pyrebase库拒绝Firebase权限

sku*_*erk 4 firebase

我已经设置了Firebase帐户和数据库.

我已将带有API密钥的配置复制到我的Python代码中.

我仍然在Python 3.5上获得401 Permission denied错误

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)
Run Code Online (Sandbox Code Playgroud)

我的数据库规则设置为:

{
 "rules": {
".read": "auth != null",
".write": "auth != null"
}
}
Run Code Online (Sandbox Code Playgroud)

imp*_*snp 10

我遇到了同样的问题,试图将数据上传到数据库.我重读了开头: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)
Run Code Online (Sandbox Code Playgroud)

将serviceAccount条目添加到配置中,其中包含可从Firebase下载的密钥的路径.

在此输入图像描述

到达目的地:设置>项目设置>服务帐户>生成新私钥.

将该密钥放在某个所需位置,并将该位置放在"serviceAccount"路径中.

希望能帮助到你.

  • 当我们成功登录时,没想到serviceAccount是必要的但是......这很有效! (2认同)