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?
Mr. Hobo
  • 530
  • 1
  • 7
  • 22
  • 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. – AKS Jul 05 '21 at 08:45
  • Yes, this sorts the problem! Thanks, @AKS. I had an impression that `;` is used to separate different variables! – Mr. Hobo Jul 05 '21 at 09:20

1 Answers1

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.

rundekugel
  • 1,118
  • 1
  • 10
  • 23