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
.
The ENVIRONMENT VARIABLES in Windows-10 is also added under GOOGLE_APPLICATION_CREDENTIALS
under System Variables:
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:
- Is this an expected behavior, and why?
- 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?