Ask coding questions

← Back to all posts
How do I use Google Auth? Python3 and Secrets JSON File.
h
xaiyeon (0)

Hello,

I have generated a Google Service Account and got the JSON file with the contents. I put most of them in .env file, but I am not sure what the best practice is to read the private key in python3.

Right now you can see some of the code on gallery.py, but my next problem is this:

    super(Client, self).__init__(
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/google/cloud/client.py", line 277, in __init__
    _ClientProjectMixin.__init__(self, project=project, credentials=credentials)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/google/cloud/client.py", line 225, in __init__
    project = self._determine_default(project)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/google/cloud/client.py", line 244, in _determine_default
    return _determine_default_project(project)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/google/cloud/_helpers.py", line 186, in _determine_default_project
    _, project = google.auth.default()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/google/auth/_default.py", line 483, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

How do I do this? I'm trying to read the documentation and it feels half-done; I just want access to Google Cloud Storage.
Thank you in advance!