Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 在VSCode调试器中设置GOOGLE_应用程序_凭据环境变量_Django_Visual Studio Code_Google Cloud Platform_Environment Variables_Vscode Debugger - Fatal编程技术网

Django 在VSCode调试器中设置GOOGLE_应用程序_凭据环境变量

Django 在VSCode调试器中设置GOOGLE_应用程序_凭据环境变量,django,visual-studio-code,google-cloud-platform,environment-variables,vscode-debugger,Django,Visual Studio Code,Google Cloud Platform,Environment Variables,Vscode Debugger,我正在使用Mac上的VSCode在Django项目上测试Google Cloud Pub/Sub,在调试测试期间设置GCP环境变量时遇到一些问题,特别是Google_应用程序_凭据环境变量 我可以在shell中设置运行服务器和/或本地测试的GOOGLE\u APPLICATION\u CREDENTIALS=“path/to/json\u credential\u file.json”的GOOGLE\u应用程序\u凭证,但由于VSCode调试器在单独的shell中运行,因此调试测试时不会设置en

我正在使用Mac上的VSCode在Django项目上测试Google Cloud Pub/Sub,在调试测试期间设置GCP环境变量时遇到一些问题,特别是
Google_应用程序_凭据
环境变量

我可以在shell中设置运行服务器和/或本地测试的
GOOGLE\u APPLICATION\u CREDENTIALS=“path/to/json\u credential\u file.json”
GOOGLE\u应用程序\u凭证
,但由于VSCode调试器在单独的shell中运行,因此调试测试时不会设置env变量。我尝试在
launch.json
中向
env
键添加相同的值:

"env": {
    "GOOGLE_APPLICATION_CREDENTIALS": "path/to/json_credential_file.json"
}
但它仍然抱怨没有设置GOOGLE_应用程序_凭据:

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.

有什么想法吗?

您可以使用启动配置,并在特定于编程语言的配置中设置“env”变量

下面是一个例子

"env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "./secret.do.not.commit/serviceAccountTasks.privateKey.json"
      }
这是参考资料