【发布时间】:2021-07-29 23:15:54
【问题描述】:
我在初始化 Firebase Admin SDK for Python 时无法设置凭据。从here 获得灵感,我是这样设置的:
import firebase_admin
from firebase_admin import credentials, firestore
cred = credentials.Certificate('./serviceAccountKey.json')
firebase_admin.initialize_app(cred)
db = firestore.Client()
...但这会导致:
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.
我可以让它工作的唯一方法是首先创建一个像这样的GOOGLE_APPLICATION_CREDENTIALS 环境变量:
export GOOGLE_APPLICATION_CREDENTIALS="serviceAccountKey.json"
对于credentials.Certificate(path)的路径,我试过'./serviceAccountKey.json'、'serviceAccountKey.json',甚至是绝对路径'/home/pi/projects/serviceAccountKey.json'
我在 Raspberry Pi 中执行此操作。
如何在不显式设置GOOGLE_APPLICATION_CREDENTIALS 环境变量的情况下使凭据工作?
【问题讨论】:
-
你试过把你的json文件直接放到initialize_app()方法中吗?通常不需要将其创建为证书,因为它依赖于不同的数据结构
-
我刚刚试了一下,得到了这个错误:
ValueError: Illegal Firebase credential provided. App must be initialized with a valid credential instance.
标签: python firebase-authentication raspberry-pi firebase-admin