nithinmurali / pygsheets

Google Sheets Python API v4

Home Page:https://pygsheets.readthedocs.io/en/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sheet reference gets ducked typed to cell reference

pungys opened this issue · comments

I encountered an issue when trying to call get_all_values() on a sheet that is a valid cell reference - such as A1(exists) or OT1(doesn't exist).

Describe the bug
Whenever I try to read data from a sheet called OT1 I get a 400 error - Range ('OT1'!OT1). This seems to be related to this google sheet bug. Apparently, the sheet name is also duck typed to a cell reference (which may not exist) and it returns 400 error. If the cell exists (such as A1) this call passes but returns unexpected results - only the contents of cell A1 in sheet A1.

Current solution
Explicitly define cell range. I replaced get_all_values() with get_values() with large enough column span.

To Reproduce
Create a worksheet with a sheet called 'OT1' then try to get_all_values().

  File "/venv/lib/python3.10/site-packages/pygsheets/worksheet.py", line 492, in get_all_values
    return self.get_values(None, None, returnas=returnas, majdim=majdim,
  File "/venv/lib/python3.10/site-packages/pygsheets/utils.py", line 180, in wrapper
    return method(self, *args, **kwargs)
  File "/venv/lib/python3.10/site-packages/pygsheets/worksheet.py", line 354, in get_values
    values = self.client.get_range(self.spreadsheet.id, grange.label, majdim,
  File "/venv/lib/python3.10/site-packages/pygsheets/client.py", line 234, in get_range
    result = self.sheet.values_get(spreadsheet_id, value_range, major_dimension, value_render_option,
  File "/venv/lib/python3.10/site-packages/pygsheets/sheet.py", line 419, in values_get
    return self._execute_requests(request)
  File "/venv/lib/python3.10/site-packages/pygsheets/sheet.py", line 495, in _execute_requests
    response = request.execute(num_retries=self.retries)
  File "/venv/lib/python3.10/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/venv/lib/python3.10/site-packages/googleapiclient/http.py", line 915, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/some-valid-id/values/OT1?majorDimension=ROWS&valueRenderOption=FORMATTED_VALUE&dateTimeRenderOption=SERIAL_NUMBER&alt=json returned "Range ('OT1'!OT1) exceeds grid limits. Max rows: 4999, max columns: 27". Details: "Range ('OT1'!OT1) exceeds grid limits. Max rows: 4999, max columns: 27">

System Information

  • OS: MacOS 12.2.1
  • pygsheets version : 2.0.5
  • pygsheets installed from (github or pypi): pypi