Search code examples
pythongoogle-sheetsgoogle-apigoogle-sheets-apigspread

Adding rows on a spreadsheet exceeds 100 sec user quota


I am writing a script in Python to add rows into a spreadsheet using gspread.

client = gspread.authorize(creds)
ws = client.open("my spreadsheet").sheet1
...

for xml in for xml in soup.findAll('items'):
  item = {
      ...
  }
  ws.append_row(item)

This work until I reach around 100 items and then it gives me an error

"error": {
"code": 429,
"message": "Insufficient tokens for quota 'WriteGroup' and limit 'USER-100s' of service 'sheets.googleapis.com' for consumer 'project_number:644051582230'.",
"status": "RESOURCE_EXHAUSTED"

Any ideas on how to write this in a different way to avoid that many requests or a way of not getting this quota limit error?


Solution

  • column_names= ['','A','B','C','D','E','F','G','H']
    cell_range = 'A1:' + str(column_names[len(items_list[0])]) + str(len(items_list))
    cells = sheet.range(cell_range)
    flattened_data = []
    
    for x in items_list:
     for y in x:
      flattened_data.append(y)
    
    
    for x in range(len(flattened_data)):
       cells[x].value = flattened_data[x].decode('utf-8')
    
    sheet.insert_row(title, index=1)
    

    That worked for me, thanks to roganshosh's comments to my question