首页 > 解决方案 > Gspread Quota 超出配额指标“读取请求”和限制“每个用户每分钟读取请求”

问题描述

cell_matrix = []
init_colnum=colnum
init_rownum=rownum

worksheet = sheet.worksheet(sheet_name)

if resize:
    worksheet.add_rows(df.shape[0]+init_colnum)
    worksheet.add_cols(df.shape[1]+init_rownum)

t_all=0
t1 = time.time()
i=1
for index,row in df.iterrows():
    print(rownum)
    if creds.access_token_expired:
        client.login()  # refreshes the token
    if i%50==0:
        worksheet.update_cells(cell_matrix)
        cell_matrix = []
        reauthorize()
        #time.sleep(120)
    if creds.access_token_expired:
        client.login()  # refreshes the token
    cellrange = '{start_col}{row}:{last_col}{row}'.format(row=rownum, start_col=get_colname_using_index(colnum), last_col=get_colname_using_index(colnum+len(row)-1))
    # get the row from the worksheet
    cell_list = worksheet.range(cellrange)
    columnnumber = 0
    for cell in row:
        if pd.isnull(cell):
            cell_list[columnnumber].value = ''
        else:
            cell_list[columnnumber].value = cell
        columnnumber += 1
    # add the cell_list, which represents all cells in a row to the full matrix
    cell_matrix = cell_matrix + cell_list
    t_all += (time.time() - t1)
    t1 = time.time()
    #sys.stdout.write("\rrownum: {}, rows: {}; avg time: {} secs; Total time: {} secs".format(rownum, i, t_all/i, t_all))
    #sys.stdout.flush()
    rownum += 1
    i+=1
# output the full matrix all at once to the worksheet.
worksheet.update_cells(cell_matrix)

if resize:
    worksheet.resize(df.shape[0]+init_rownum-1, df.shape[1]+init_colnum-1)

上面的代码抛出以下错误:gspread.exceptions.APIError: {u'status': u'RESOURCE_EXHAUSTED', u'message': u"配额指标“读取请求”和限制“每个用户每分钟读取请求”的配额超出'消费者'project_number:1044022051760'的服务'sheets.googleapis.com'。", u'code': 429, u'details': [{u'reason': u'RATE_LIMIT_EXCEEDED', u'@type': u'type.googleapis.com/google.rpc.ErrorInfo', u'domain': u'googleapis.com', u'metadata': {u'quota_metric': u'sheets.googleapis.com/read_requests', u '消费者':u'projects/1044022051760',u'service':u'sheets.googleapis.com',u'quota_limit':u'ReadRequestsPerMinutePerUser'}}]}

标签: google-sheetsgoogle-sheets-apigspread

解决方案


推荐阅读