初始化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'
我在树莓皮里面做这个
如何在不显式设置GOOGLE_APPLICATION_CREDENTIALS
环境变量的情况下使凭据正常工作
您可以使用
environ
在本地设置环境变量或
相关问题 更多 >
编程相关推荐