Google sheets python API - module 'google.auth.credentials' has no attribute 'CredentialsWithTokenUri'

179 views Asked by At

I'm trying to set up the Google Sheets API for python. When I run the quickstart.py file (exactly as specified in the google documentation), I receive the following error:

AttributeError: module 'google.auth.credentials' has no attribute 'CredentialsWithTokenUri'

I've followed the instructions from https://developers.google.com/sheets/api/quickstart/python.

Installed the necessary packages, created a project in the Google Cloud console, enabled the sheets API, filled out the OAuth consent, created credentials, saved the credentials.json into my working directory.

I'm unable to run Python quickstart.py or Python 3 quickstart.py - I receive the error each time.

I'm not sure what the error means or where to start. Any help is appreciated?

Full error message below:

Traceback (most recent call last):
  File "/Users/heshimuntiu/Desktop/scripts/googleSheetsAutomation/quickstart.py", line 5, in <module>
    from google_auth_oauthlib.flow import InstalledAppFlow
  File "/Users/heshimuntiu/opt/anaconda3/lib/python3.9/site-packages/google_auth_oauthlib/__init__.py", line 21, in <module>
    from .interactive import get_user_credentials
  File "/Users/heshimuntiu/opt/anaconda3/lib/python3.9/site-packages/google_auth_oauthlib/interactive.py", line 27, in <module>
    import google_auth_oauthlib.flow
  File "/Users/heshimuntiu/opt/anaconda3/lib/python3.9/site-packages/google_auth_oauthlib/flow.py", line 68, in <module>
    import google_auth_oauthlib.helpers
  File "/Users/heshimuntiu/opt/anaconda3/lib/python3.9/site-packages/google_auth_oauthlib/helpers.py", line 27, in <module>
    from google.auth import external_account_authorized_user
  File "/Users/heshimuntiu/opt/anaconda3/lib/python3.9/site-packages/google/auth/external_account_authorized_user.py", line 52, in <module>
    credentials.CredentialsWithTokenUri,
AttributeError: module 'google.auth.credentials' has no attribute 'CredentialsWithTokenUri'
1

There are 1 answers

0
Samantra On

TL;DR: update to Python 3.10+.

As of Jan 2024, the instructions you mentioned states:

Prerequisites: Python 3.10.7 or greater, ...

I checked which version of Python I run.
I have exactly the same error on Python 3.9.2 and no error on Python 3.10.11.