1

I am trying to check the date of the latest modification to a google sheet using pygsheets 1.1.4, google-api-python-client 1.6.7, and Python 3.6.3 on Windows 10.

I can authenticate, view, and edit spreadsheet contents, but when I try to get the last-modified date:

my_client = pygsheets.authorize(service_file=secret_service_acct_file)
my_worksheet = my_client.open_by_key(my_key)
last_updated = my_worksheet.updated

I instead get the following error:

Traceback (most recent call last):
  File "<pyshell#77>", line 1, in <module>
    my_worksheet.updated
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pygsheets\spreadsheet.py", line 90, in updated
    response = self.client._execute_request(self.id, request, False)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\pygsheets\client.py", line 459, in _execute_request
    response = request.execute()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\googleapiclient\http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files/{API_KEY}?fields=modifiedTime&supportsTeamDrives=false&alt=json returned "File not found: {API_KEY}.">

This, to me, indicates that the file is not found. I would expect other read/write operations to fail if the authorization or the connection had some issue. I have tried opening the spreadsheet with open_by_url() instead, but received the same results.

I am using google-api-python-client v1.6.7 and pygsheets v1.1.4, freshly installed from GitHub. I have tried running in "administrator" mode and running with no_cache=True, as per suggestions in other questions like this one, to no avail.

I was using gspread 0.6.2 until I realized I would eventually need "Team Drive" support. gspread 3.0.0 claims to offer "Team Drive" support, but also deprecated the .updated attribute that I need.

How can I get my latest modifiedTime with pygsheets, or should I be using a different library altogether?

edit: I noticed that pygsheets uses the v3 Sheets API for the attribute I'm trying to call, and another SO answer describes the removal of "file oriented" options between the v3 Sheets API and the v4 Sheets API, but the migration guide from google doesn't seem to have any hints for my use case.

tehhowch
  • 9,645
  • 4
  • 24
  • 42
Crowhill
  • 11
  • 3
  • are you able to do make other requests? like `my_worksheet.sheet1.update_value('A1',"test")` ? I am unabel to reproduce your error. – Nithin May 17 '18 at 11:55
  • 1
    If your sheet is in a team drive you would need to turn on teamdirve. Its not turned on by default. – Nithin May 17 '18 at 12:00
  • Pygsheets uses Sheets API from Google. You can try if the file really exist in the [spreadsheets.values.update](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update) Try-it. – ReyAnthonyRenacia May 17 '18 at 12:22
  • @noogui Yes, I can make updates using the Python sample for the v4 Sheets API on that page, so I believe that my file exists. – Crowhill May 17 '18 at 18:00
  • Thanks, @nithin for prompting me to double check the teamdrive settings. Someone on the team did move the file into teamdrives without my knowledge, and setting enableTeamDriveSupport=True resolved my issue. – Crowhill May 17 '18 at 18:46

0 Answers0