Python GCP API not able to read environmental values

156 views Asked by At

Developing a DLP client and Setting GOOGLE_APPLICATION_CREDENTIALS using win shell.

API is failing with following signature:

google.auth.exceptions.DefaultCredentialsError: File "XXXXX.json" was not found.

When set in code using

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "XXXXX.json" it works fine.

OS used windows 10.

Can any one explain the reason?

Updates

  1. I did set environment variable from pycharm terminal.
  2. I am running the code from pycharm terminal: python my_code.py
  3. When i print(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) i get the value i did set.
1

There are 1 answers

0
Arnab Mukherjee On BEST ANSWER

Issue Found:

Environmental variable was set using quotes. It should be without quotes.

set GOOGLE_APPLICATION_CREDENTIALS="path\to\secret\key"

Confusing debug message

google.auth.exceptions.DefaultCredentialsError: File "path\to\secret\key" was not found.

Resolution:

set GOOGLE_APPLICATION_CREDENTIALS=path\to\secret\key