0

I wanted to explore Google Big-Query with Python, and as per this tutorial I have set up a Google Cloud Account (free-tier), and have generated a key. The JSON file is stored in D:\keys\quixotic-folio-318907-64bfdccfb050.json.

enter image description here

The ENVIRONMENT VARIABLES in Windows-10 is also added under GOOGLE_APPLICATION_CREDENTIALS under System Variables:

enter image description here

However, whenever I try to initialize the client, it throws an error - File Not Found:

> from google.cloud import storage > storage.Client(project = "quixotic-folio-318907") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Anaconda3\lib\site-packages\google\cloud\storage\client.py", line 123, in __init__ super(Client, self).__init__( File "D:\Anaconda3\lib\site-packages\google\cloud\client.py", line 319, in __init__ Client.__init__( File "D:\Anaconda3\lib\site-packages\google\cloud\client.py", line 178, in __init__ credentials, _ = google.auth.default(scopes=scopes) File "D:\Anaconda3\lib\site-packages\google\auth\_default.py", line 454, in default credentials, project_id = checker() File "D:\Anaconda3\lib\site-packages\google\auth\_default.py", line 221, in _get_explicit_environ_credentials credentials, project_id = load_credentials_from_file( File "D:\Anaconda3\lib\site-packages\google\auth\_default.py", line 107, in load_credentials_from_file raise exceptions.DefaultCredentialsError( google.auth.exceptions.DefaultCredentialsError: File D:\keys\quixotic-folio-318907-64bfdccfb050.json; was not found. 

I've tried os method, as suggested here, and it is running perfectly:

> import os > from google.cloud import storage > os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = "D:\keys\quixotic-folio-318907-64bfdccfb050.json" > storage.Client(project = "quixotic-folio-318907") <google.cloud.storage.client.Client object at 0x000002448A4E8AF0> 

I have the following questions:

  1. Is this an expected behavior, and why?
  2. How do I ensure that I do not have to specifically set os.environ['GOOGLE_APPLICATION_CREDENTIALS'] as it is already defined under System Variables?
2
  • 2
    Can you try removing the trailing semicolon from the env variable value? The error which is generated also has that trailing semicolon but when you test separately using storage you didn't specify semicolon; and it could be that is causing this error because it is trying to search for the filename with the semicolon. Commented Jul 5, 2021 at 8:45
  • Yes, this sorts the problem! Thanks, @AKS. I had an impression that ; is used to separate different variables! Commented Jul 5, 2021 at 9:20

1 Answer 1

1

Remove the

; 

at the end of your path in the environment variable.

Edit: User AKS was faster than me. @AKS: If you write your comment in an answer, it can be marked as solved.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.