我正在使用VSCode在Mac上测试我的Django项目中的Google Cloud Pub/Sub,并且在调试测试期间设置GCP环境变量时遇到了一些问题,具体是GOOGLE_APPLICATION_CREDENTIALS
环境变量。
我可以在shell中使用export GOOGLE_APPLICATION_CREDENTIALS="path/to/json_credential_file.json"
为运行服务器和/或本地测试设置GOOGLE_APPLICATION_CREDENTIALS
,但是由于VSCode调试器在单独的shell中运行,因此在调试测试时未设置env变量。我尝试将相同的值添加到launch.json
的env
键中:
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "path/to/json_credential_file.json"
}
但它仍然抱怨 GOOGLE_APPLICATION_CREDENTIALS 没有设置:
oauth2client.client.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.
有什么想法吗?