无法使用Python为Cloud Firestore设置serviceAccountKey

2024-09-28 22:21:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试访问我的Firebase项目的cloudfirestore数据库。我有一个非常简单的代码,我只想连接到我的数据库并向其中添加一些内容,但不幸的是,我无法正确设置serviceAccountKey,因此我得到以下错误:

raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.

当然,我理解这条消息,并且我访问了the Google Developers link,但是我没有找到任何对我的案例有用的东西。在

必须补充的是,我正在尝试this Firebase tutorial,所以我遵循了它的示例代码,它使用serviceAccountKey.json文件进行验证。在

下面是给出错误的代码:

^{pr2}$

我已经试用了两个不同的帐户密钥,从Firebase admin的两个不同位置下载。我假设正确的一个是我在Settings > Service Accounts > Firebase Admin SDK找到的,所以我下载了生成的密钥,复制到我的apps文件夹,并将其重命名为serviceAccountKey.json,然后运行代码并从问题顶部得到错误。在

如果有更多关于这个主题的经验的人能告诉我是否在代码中犯了一个明显的错误,或者有什么其他的建议可以帮助我解决这个问题,我将非常感激。在


Tags: the项目代码数据库jsonapplication错误service