认证的python firestore问题 [英] python firestore issue with authentication
问题描述
我在firestore中使用python,并尝试在后端创建客户端.我正在关注本教程
I am using python with firestore, and trying to create a client in the backend. I am following this tutorial
具有以下代码
import firebase_admin
from firebase_admin import credentials, firestore
cred = credentials.Certificate("cred_file.json")
firebase_admin.initialize_app(cred)
db = firestore.Client()
ref = db.collections(u'table')
并出现以下错误
google.auth.exceptions.DefaultCredentialsError:无法 自动确定凭据.请设定 GOOGLE_APPLICATION_CREDENTIALS或显式创建凭据和 重新运行该应用程序.有关更多信息
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information
我猜默认凭据有问题,我没有得到,如果我在代码中初始化凭据,为什么应用程序对默认凭据不断抛出错误?我明确为其提供了正确的cred文件.
I guess that is something wrong with the default credentials, what I don't get is, if I am initializing the credentials in my code, why does the app keep throwing an error for the default credentials? I am giving it the proper cred file explicitly.
推荐答案
您需要下载服务帐户密钥(JSON文件),然后将GOOGLE_APPLICATION_CREDENTIALS环境变量设置为指向设备上的该文件.
You need to download a service account key (a JSON file) then set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to that file on your device.
credential_path = "D:\****.json"
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credential_path
别忘了通过import os
请参见 https://cloud.google.com/firestore/docs/quickstart-服务器以获取更多详细信息.
See https://cloud.google.com/firestore/docs/quickstart-servers for more details.
这篇关于认证的python firestore问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!