3

After 2 days of reading gspread docs, gspread blog posts, and following the most recent docs for using gspread I'm still not able to open even one Google Spreadsheet. I set up a GDrive API service account. It appears that my OAuth2 credentials are working, but I'm still getting constant 'SpreadsheetNotFound' errors.

My code looks something like this, and runs with no error message until it tries to open the Google Spreadsheet:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

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

jsonfile    = '/path/Python-data-GSpreadsheets-dbbc-99.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(jsonfile,scope)

# get authorized to access data
gc = gspread.authorize(credentials)
# gc returns with no error messages, so far OK
wks = gc.open('SSTEst123').sheet1  #fails here
#throws SpreadsheetNotFound error

Yes, I've added my gmail email address as authorized to edit (tried it with and without) since the service account should be able to access all my data anyway, and I'm resharing my spreadsheet with myself.

What else can I try to discover why it is failing? Any ideas on how to debug why it can't open any spreadsheet?

OK, here's how I solved it. Had to share my spreadsheets with the Google Drive API service account 'email address' (e.g. my.test.data@python-xyz-gspreadsheets.iam.gserviceaccount.com ) -- (Thought it was my 'real' gmail ID/email, but it wasn't)

For debugging the feed ... Added a few print() lines in the gspread client.py source to see if I was getting anything in the feed, and to check the values from the feed. Noticed that I was getting a value that was old value (from previous script?)

Shut down and restarted my iPython notebook, and it's working now.

BigDoug
  • 31
  • 4

1 Answers1

0

OK, problem solved. Here's what I did to figure it out:

Added a few print() lines in the client.py source to see if I was getting anything in the feed, and to check the values from the feed. Noticed that I was getting a value that was old value (from previous script?)

Shut down and restarted my iPython notebook, and it's working now.

BigDoug
  • 31
  • 4
  • Could you elaborate a little on how you think you got this working and what you were able to learn from the print statements? I'm having the exact same problem you described above. It doesn't appear clear to me that my GDrive app has access to "my" google docs. – robertwest Apr 18 '16 at 20:12
  • Nevermind! Got it working! Using the same documentation you mentioned: http://gspread.readthedocs.org/en/latest/oauth2.html#using-signed-credentials – robertwest Apr 18 '16 at 20:25
  • Also had to share my spreadsheets with the Google Drive API service account 'email address' (e.g. my.test.data@python-xyz-gspreadsheets.iam.gserviceaccount.com ) – BigDoug Apr 19 '16 at 15:12