在使用本地Firestore仿真器时,需要提供适当的凭据来进行身份验证,以便访问模拟的数据库。如果未提供凭据,或者凭据不正确,则会发生DefaultCredentialsError错误。
要解决此问题,请使用以下代码示例,设置Firestore仿真器的凭据:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
# Set the path to the credential file
cred = credentials.Certificate("path/to/credential/file.json")
# Initialize the app with the credential
firebase_admin.initialize_app(cred)
# Set the Firestore emulator URL
db = firestore.client()
db.settings(host='localhost:8080',ssl=False)
要使用此代码示例,将以下内容替换为实际信息:
通过提供凭据和使用正确的URL,您应该能够消除DefaultCredentialsError错误并成功连接到本地Firestore仿真器。
上一篇:本地Firebase函数正常工作,但在调用部署的服务器版本时返回“错误:“MODULE_NOT_FOUND””。
下一篇:本地Flask/Flask容器可以连接到远程MariaDB,但在远程Ubuntu主机上的Flask容器却无法连接。