. 我尝试执行以下代码行: -6ren">
gpt4 book ai didi

python - "No such file or directory"与 firebase_admin python 库

转载 作者:行者123 更新时间:2023-12-01 09:19:37 25 4
gpt4 key购买 nike

我想使用 python 官方库 (firebase_admin) 而不是 pyrebasepython-firebase 通过 Firebase 数据库检索一些数据>.

我尝试执行以下代码行:

from firebase_admin import db
from firebase_admin import credentials
import firebase_admin

cred = credentials.Certificate('https://project_name.firebaseio.com/.json')
firebase_admin.initialize_app(cred)

result = db.Query.get()

但是我收到以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'https://project_name.firebaseio.com/.json'

即使当我在浏览器上输入此网址(将 project_name 替换为我的真实项目名称)时,我还是从数据库中获取了 json 数据。

如何修复此错误?

最佳答案

证书应指向包含您的凭据/证书的本地文件。相反,您将其指向数据库 URL,该 URL 不是本地文件,因此库会抛出错误。

来自documentation on initializing the Python SDK :

import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

# Fetch the service account key JSON file contents
cred = credentials.Certificate('path/to/serviceAccountKey.json')

# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://databaseName.firebaseio.com'
})

# As an admin, the app has access to read and write all data, regardless of Security Rules
ref = db.reference('restricted_access/secret_document')
print(ref.get())

关于python - "No such file or directory"与 firebase_admin python 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50908486/

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