Adding rows on a spreadsheet exceeds 100 sec user quota

微笑、不失礼 提交于 2019-12-13 02:44:05

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/52447671/adding-rows-on-a-spreadsheet-exceeds-100-sec-user-quota

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!