问题
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