Invalid JSON payload received. Unexpected token. error when bulk uploading with update_cells(cell_list)
See original GitHub issueHello,
I started getting the error when I updated to Python 3.7 two days ago. I use the following code to upload a pandas df to a gsheet - the error happens with any df.
Re the error: this seems to pertain to some cells with value ‘180901_millbrae_1’, may or may not be relevant. This exact same data and code used to work fine.
Any ideas?
Error:
Traceback (most recent call last):
File "<ipython-input-31-85b52784b441>", line 11, in <module>
ws.update_cells(cell_list)
File "/Users/../anaconda/lib/python3.7/site-packages/gspread/models.py", line 782, in update_cells
'values': values_rect
File "/Users/../anaconda/lib/python3.7/site-packages/gspread/models.py", line 176, in values_update
r = self.client.request('put', url, params=params, json=body)
File "/Users/../anaconda/lib/python3.7/site-packages/gspread/client.py", line 79, in request
raise APIError(response)
APIError: {
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unexpected token.\nae\", 43344, \"None\", NaN], [\"180901_millb\n ^",
"status": "INVALID_ARGUMENT"
}
}
Code:
n_rows, n_cols = df.shape
k = 1000
for i in range(n_rows//k + 1):
row0 = start_row + i*k
col0 = start_col
row1 = start_row + min((i+1)*k, n_rows-1)
col1 = start_col + n_cols - 1
cell_list = ws.range(inputRange(row0, col0, row1, col1))
for cell in cell_list:
val = df.iloc[cell.row-start_row, cell.col-start_col]
cell.value = val
ws.update_cells(cell_list)
Operating System: macOS Sierra 10.12.6 Python version: 3.7.0 gspread version: 3.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Getting error {{'code': 400, 'message': 'Invalid JSON payload ...
I am trying to run the following code for googleautoreply but it is giving the error 'Invalid JSON payload received.
Read more >Invalid JSON payload received. Unexpected token. error when ...
Hello,. I started getting the error when I updated to Python 3.7 two days ago. I use the following code to upload a...
Read more >Recieved error - Invalid JSON payload received, when trying ...
( 1 ), the error thrown is : Invalid JSON payload received. Unexpected token. Note: (1)Oauth credentials are checked and correct,. google access...
Read more >Google Ads API and Invalid JSON payload received ... - Reddit
Google Ads API and Invalid JSON payload received. Unexpected token. I'm getting the following error when try to run my report that was ......
Read more >Google Sheets - JSON Format | Blue Prism Product
Internal : Unexpected error Error during Web API HTTP Request HTTP Status Code: 400 ... "message": "Invalid JSON payload received. Unexpected token.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, I encountered the same problem. I filled up ‘NaN’ values with empty string,
df.fillna('', inplace=True)
and the problem was solved.I found an alternate solution that preserves the numeric data type of numeric columns:
Probably quite slow if your sheet is large but it works 🤷♂️