I am using python 2.7 on a Raspberry Pi with version 3.0.0 of gspread.
When I use gspread's get_all_values() function, I get the following error:
File "/home/pi/DB/GSheets/GoogleSheets.py", line 121, in GetAll
listOfLists = googleSheetName.worksheet(GSTabName).get_all_values()
File "/home/pi/.local/lib/python2.7/site-packages/gspread/models.py", line 444, in get_all_values
data = self.spreadsheet.values_get(self.title)
File "/home/pi/.local/lib/python2.7/site-packages/gspread/models.py", line 110, in values_get
r = self.client.request('get', url, params=params)
File "/home/pi/.local/lib/python2.7/site-packages/gspread/client.py", line 79, in request
raise APIError(response)
gspread.exceptions.APIError: {
"error": {
"code": 400,
"message": "Range ('name'!name) exceeds grid limits. Max rows: 52, max columns: 17",
"status": "INVALID_ARGUMENT"
}
}
This issue did not occur for me in a previous version of gspread. The current version, previously known as "v4", seems to have introduced this. As far as I can tell, the get_all_values function has not changed between the two versions. Does anyone know what might be causing this suddenly?
Thanks in advance!
EDIT:
'name' is being used as a placeholder for the worksheet's name.
EDIT2:
Note: I have connected the project to a completely new Google Sheet with identical worksheets (and names) and the error still occurs. All of the worksheet names are alphanumeric and contain no spaces or special characters.
EDIT3:
The name of the tab that it gets stuck on is in the form of "ABC1", but this is the first tab that gets read.
After changing it to "SheetA", if response.ok:
in client.py succeeds 4 times and then MySQLdb crashes due to an SQL syntax error in its own distribution files (likely caused by bad data being used to build a command). Before changing the tab name to be "SheetA", response.ok would succeed 3 times and then fail. When I force the exception to not be thrown, the data sent (a list of lists containing the worksheet values) is no different than what is sent when the exception is not triggered.
The actual dimension of the worksheet are 52 x 17 (rows x columns). The dimensions in the APIError always match the dimensions of the worksheet.
EDIT4:
This has been discovered: The following worksheet (tab) name formats throw an APIError (code 400): "ABC1", "ABC123", however "ABCD123" or "ABC1D" work. I also noticed that when I move a worksheet/tab with a valid name (Called FirstSheet below) before a worksheet with a non-valid name that the error thrown includes the FirstSheet name like this: read.exceptions.APIError: { "error": { "code": 400, "message": "Range (FirstSheet!ABC123) exceeds grid limits. Max rows: 132, max columns: 17", "status": "INVALID_ARGUMENT" }
, but only upon crashing at the non-valid name. The previous, valid, worksheets are read without issue.
The worksheets all vary in size.
I had the same issue, although my code was in ruby. Underscores did not work.
What happens is that google gets confused when the file name ends with an integer, for example your sheet name is called ABC123
. So ABC123X
would had worked fine.
To fix it I had to escape it using single quotes - FirstSheet!'ABC123'
My code looked something like this:
service.get_spreadsheet(file_id, ranges: "'ABC123'")
I'm unsure why this works, but a workaround that I discovered is to surround the worksheet name(s) with underscores (in Google Sheets):
_Worksheet1_
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With