在VSCode调试器中设置GOOGLE_APPLICATION_CREDENTIALS环境变量

3

我正在使用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.jsonenv键中:

"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.

有什么想法吗?
3个回答

2

2

0
在Powershell中运行以下命令: [Environment]::SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "path\serviceAccountTasks.privateKey.json", "User") 这将为所有进程设置环境变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接