3

I'm struggling to get access to a google spreadsheet with python 2.7 using gspread.

Here's what I have so far:

import gspread
from oauth2client.service_account import ServiceAccountCredentials



scope = ['https://spreadsheets.google.com/feeds']

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'credentials.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open("PracticeOpsBS").sheet1

The result is a bunch of stuff that I think is showing me what is going on, resulting in the following:

"HttpAccessTokenRefreshError: invalid_grant: Invalid JWT Signature."

Ultimately I'm hoping to access the information from two tabs of this worksheet to do some analysis, but haven't been able to pull the data in to python from google. Any help is appreciated and I'll answer any clarifying questions as I can!

Nick
  • 41
  • 7
  • Is your computer indicating the right time ? http://stackoverflow.com/a/36201957/1388292 – Jacques Gaudin Jun 09 '16 at 18:13
  • @JacquesGaudin Computer time lines up with perfectly with NIST time – Nick Jun 09 '16 at 18:32
  • 1
    I presume that you have already tried with a different json file. Can you add the exact traceback and check your `credentials.json` for `tokenexpired` field ? – Jacques Gaudin Jun 10 '16 at 00:24
  • @JacquesGaudin, I'm new to all this. Tried a different .json with no luck. Ended up downgrading oauth2client to version 1.5.1 and was able to get in. Thanks for the help! – Nick Jun 10 '16 at 20:15
  • Good that you solved it I was a bit clueless on this one. – Jacques Gaudin Jun 11 '16 at 09:15

1 Answers1

1

Looks like it was an issue with the version of oauth2client that I was using. To get things to work, I downgraded to oauth2client version 1.5.1. Then I used the following to gain access to the spreadsheet:

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('credentials.json'))
scope = ['https://spreadsheets.google.com/feeds']

credentials = SignedJwtAssertionCredentials(
    json_key['client_email'], json_key['private_key'], scope)


gc = gspread.authorize(credentials)

wks = gc.open('PracticeOpsBS')
Nick
  • 41
  • 7
  • 1
    While this fix may work, SignedJwtAssertionCredentials has been deprecated. It is recommended that you migrate to ServiceAccountCredentials: https://github.com/google/oauth2client/issues/401 – bruntime Jun 06 '17 at 15:19