question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

oauth2client is deprecated, can we use its replacement, google-auth?

See original GitHub issue

Environment info

Operating System: osx Python version: 3.6 gspread version: latest

Steps to reproduce

Oauth2client documentation says it’s deprecated and we should be using google-auth

If you try to establish credentials with

credentials = service_account.Credentials.from_service_account_file(
    'service-account.json')

gc = gspread.authorize(credentials)

You’ll get this error:

Traceback (most recent call last):
  File "spreadsheet.py", line 19, in <module>
    gc = gspread.authorize(credentials)
  File "/usr/local/lib/python3.6/site-packages/gspread/client.py", line 402, in authorize
    client.login()
  File "/usr/local/lib/python3.6/site-packages/gspread/client.py", line 56, in login
    if not self.auth.access_token or \
AttributeError: 'Credentials' object has no attribute 'access_token'

Obviously, the google creditials json file doesn’t have an ‘access_token’ key, so something is amiss there.

If I instead use the deprecated

scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('service-account.json', scope)
gc = gspread.authorize(credentials)

It works fine.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

17reactions
zenixls2commented, Jul 25, 2017

if you want to integrate with google_auth, I suggest you to do with the session provided by google_auth:

from google.auth.transport.requests import AuthorizedSession
gc = gspread.Client(auth=credentials)
gc.session = AuthorizedSession(credentials)
sheet = gc.open_by_key(spreadsheetId)
print sheet.title

refer to https://google-auth.readthedocs.io/en/latest/user-guide.html and this should work the same as before. just notice that session is from Requests and not httplib2.

0reactions
sboissoncommented, Mar 3, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

oauth2client deprecation — google-auth 1.30.0 documentation
Instead, we've chosen to create a new replacement library that can live side-by-side with oauth2client and allow users to migrate gradually.
Read more >
python - oauth2client is now deprecated - Stack Overflow
I was googling to find a solution how to replace the parts of code where oauth2client is being used. Yet since I am...
Read more >
oauth2client is deprecated, can we use its replacement, google-auth?
Oauth2client documentation says it's deprecated and we should be using google-auth. If you try to establish credentials with credentials = service_account.
Read more >
OAuth 2.0 for Client-side Web Applications | Authorization
This document explains how to implement OAuth 2.0 authorization to access Google APIs from a JavaScript web application.
Read more >
CHANGELOG
Note: oauth2client is deprecated. No more features will be added to the libraries and the core team is turning down support. We recommend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found