python firestore issue with authentication

假装没事ソ 提交于 2020-01-04 05:58:10

问题


I am using python with firestore, and trying to create a client in the backend. I am following this tutorial

with the following code

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')

and getting the following error

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

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.


回答1:


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

Don't forget to import the library os by import os

See https://cloud.google.com/firestore/docs/quickstart-servers for more details.



来源:https://stackoverflow.com/questions/54947486/python-firestore-issue-with-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!