【发布时间】:2018-06-15 21:33:19
【问题描述】:
我有一个应用程序偶然使用了公共 youtube API 数据,而不是与用户相关的数据。
第 1 阶段:从命令行运行
在我的youtube_module.py 顶部,我有:
from oauth2client.client import GoogleCredentials
CREDENTIALS = GoogleCredentials.get_application_default()
根据文档要求,在.bashrc 我设置:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
api 调用成功,一切正常。
第 2 阶段:使用 Flask 和 Gunicorn 运行。
现在我正在浏览器上测试应用程序。当我通过Gunicorn 和$ gunicorn app:app --workers 16 (Listening at: http://127.0.0.1:8000) 运行Flask 应用程序(Listening at: 127.0.0.1:5000) 时
该应用提供了几个页面,但随后遇到以下错误:
ApplicationDefaultCredentialsError: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
credentials.json 却在同一条路径上。
如何在Flask 中正确设置GOOGLE_APPLICATION_CREDENTIALS?
【问题讨论】:
标签: python flask gunicorn youtube-data-api