【发布时间】:2017-04-10 19:27:23
【问题描述】:
我想在我的 Python 应用程序中使用 Google Translate API,并且我已经阅读了文档,并且我已经设置了我的服务帐户并现在根据我应该运行的文档下载了 JSON 文件:
$ export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
现在我正在 Windows 机器上进行开发,我尝试使用
>setx GOOGLE_APPLICATION_CREDENTIALS "<path_to_service_account_file>"
它成功了,但是当我尝试创建翻译对象时,我不断收到以下错误:
from google.cloud import translate
trans = translate.Client()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\translate\client.py", line 66, in __init__
super(Client, self).__init__(credentials=credentials, _http=_http)
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\client.py", line 128, in __init__
credentials = get_credentials()
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\cloud\credentials.py", line 39, in get_credentials
credentials, _ = google.auth.default()
File "C:\Users\achim\Envs\expert-farmer\lib\site-packages\google\auth\_default.py", line 282, in default
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.
【问题讨论】:
-
set GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>然后运行你的 python 应用程序工作吗? -
我试过了,但又遇到了一个错误
-
rmeertens 谢谢你,我试过不带引号,它有效