Google表更新由于速率限制而导致的错误和Python代码

发布于 2025-01-22 05:52:45 字数 1786 浏览 1 评论 0 原文

我正在尝试使用Python玩Google表格,但这给了我错误。这可能是由于没有优化代码逻辑。

错误

gspread.exceptions.apierror:{'code':429,'消息':“配额指标'写入请求'超过配额,并限制'service'seervice'seervice'seervice'shees.googleapis.com' 。 。 >

shop_names = ['wilmermobel', 'masonheron', 'flashree', 'jochiwon', 'senangku', 'dutchgaming', 'hiranai', 'chairsy', 'genelotrics', 'bahemas', 'gameniture', 'martenkaiser', 'secretracer']
web_data_non_ful = ['0', '5.13', '0', '0', '0.00', '0.00', '0', '0', '6.25', '0.58', '0', '0', '0.00']
web_data_late_ship = ['0', '8.89', '0', '0', '8.33', '0.00', '0', '0', '0', '1.51', '0', '0', '0.00']
web_data_pre_time = ['0', '1.50', '2.02', '1.49', '2.17', '0.93', '2.04', '0.94', '1.30', '1.77', '', '', '1.07']
web_data_resp_rate = ['57.00', '96.01', '95.45', '100.00', '98.26', '98.32', '92.97', '91.05', '98.70', '97.44', '100.00', '57.00', '97.04']
web_data_shop_rate = ['0', '4.85', '5.00', '5.00', '4.70', '4.78', '4.89', '4.74', '4.88', '4.74', '5.00', '0', '4.71']
web_data_penal_points = ['0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0']

def sheet_updater('sheet1', col_num, col_data):

    for cn, cd in zip(col_num, col_data):
        try:
            r = 2
            x = 0
            for i in range(13):
                try:
                    time.sleep(1)
                    t = sheet.update_cell(r, cn, cd[x])
                    print(t)
                    r += 1
                except:
                    pass
                x += 1
        except:pass


col_data = [shop_names, web_data_non_ful, web_data_late_ship,web_data_pre_time, web_data_resp_rate, web_data_shop_rate, web_data_penal_points]
col_num = [1, 2, 3, 4, 5, 6, 7]
sheet_updater('sheet1', col_num, col_data)
   

I am trying to play with google Sheets using python but it is giving me the error. It may be due to not having optimizing code logic.

Error

gspread.exceptions.APIError: {'code': 429, 'message': "Quota exceeded for quota metric 'Write requests' and limit 'Write requests per minute per user' of service 'sheets.googleapis.com' for .", 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'RATE_LIMIT_EXCEEDED', 'domain': 'googleapis.com', 'metadata': {'quota_limit': 'WriteRequestsPerMinutePerUser',, 'quota_metric': 'sheets.googleapis.com/write_requests', 'service': 'sheets.googleapis.com'}}]}

shop_names = ['wilmermobel', 'masonheron', 'flashree', 'jochiwon', 'senangku', 'dutchgaming', 'hiranai', 'chairsy', 'genelotrics', 'bahemas', 'gameniture', 'martenkaiser', 'secretracer']
web_data_non_ful = ['0', '5.13', '0', '0', '0.00', '0.00', '0', '0', '6.25', '0.58', '0', '0', '0.00']
web_data_late_ship = ['0', '8.89', '0', '0', '8.33', '0.00', '0', '0', '0', '1.51', '0', '0', '0.00']
web_data_pre_time = ['0', '1.50', '2.02', '1.49', '2.17', '0.93', '2.04', '0.94', '1.30', '1.77', '', '', '1.07']
web_data_resp_rate = ['57.00', '96.01', '95.45', '100.00', '98.26', '98.32', '92.97', '91.05', '98.70', '97.44', '100.00', '57.00', '97.04']
web_data_shop_rate = ['0', '4.85', '5.00', '5.00', '4.70', '4.78', '4.89', '4.74', '4.88', '4.74', '5.00', '0', '4.71']
web_data_penal_points = ['0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0']

def sheet_updater('sheet1', col_num, col_data):

    for cn, cd in zip(col_num, col_data):
        try:
            r = 2
            x = 0
            for i in range(13):
                try:
                    time.sleep(1)
                    t = sheet.update_cell(r, cn, cd[x])
                    print(t)
                    r += 1
                except:
                    pass
                x += 1
        except:pass


col_data = [shop_names, web_data_non_ful, web_data_late_ship,web_data_pre_time, web_data_resp_rate, web_data_shop_rate, web_data_penal_points]
col_num = [1, 2, 3, 4, 5, 6, 7]
sheet_updater('sheet1', col_num, col_data)
   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个ˇ局外人 2025-01-29 05:52:45

在您的脚本中,下面的修改如何?

修改后的脚本:

shop_names = ['wilmermobel', 'masonheron', 'flashree', 'jochiwon', 'senangku', 'dutchgaming', 'hiranai', 'chairsy', 'genelotrics', 'bahemas', 'gameniture', 'martenkaiser', 'secretracer']
web_data_non_ful = ['0', '5.13', '0', '0', '0.00', '0.00', '0', '0', '6.25', '0.58', '0', '0', '0.00']
web_data_late_ship = ['0', '8.89', '0', '0', '8.33', '0.00', '0', '0', '0', '1.51', '0', '0', '0.00']
web_data_pre_time = ['0', '1.50', '2.02', '1.49', '2.17', '0.93', '2.04', '0.94', '1.30', '1.77', '', '', '1.07']
web_data_resp_rate = ['57.00', '96.01', '95.45', '100.00', '98.26', '98.32', '92.97', '91.05', '98.70', '97.44', '100.00', '57.00', '97.04']
web_data_shop_rate = ['0', '4.85', '5.00', '5.00', '4.70', '4.78', '4.89', '4.74', '4.88', '4.74', '5.00', '0', '4.71']
web_data_penal_points = ['0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0']

def sheet_updater(shop_names, col_num, col_data):
    values = []
    for cn, cd in zip(col_num, col_data):
        try:
            temp = []
            r = 2
            x = 0
            for i in range(13):
                try:
                    temp.append(cd[x])
                    r += 1
                except:
                    pass
                x += 1
            values.append(temp)
        except:
            pass
    return [list(x) for x in zip(*values)]

col_data = [shop_names, web_data_non_ful, web_data_late_ship,web_data_pre_time, web_data_resp_rate, web_data_shop_rate, web_data_penal_points]
col_num = [1, 2, 3, 4, 5, 6, 7]
res = sheet_updater('sheet1', col_num, col_data)
sheet.update('A1', res, value_input_option='USER_ENTERED')
  • 在此修改中,将值放在列表中,并使用Sheet Sheet API将列表放在电子表格中。通过此流程,通过一个API调用将值放入电子表格中。这样,我认为您的问题可以被删除。

参考:

In your script, how about the following modification?

Modified script:

shop_names = ['wilmermobel', 'masonheron', 'flashree', 'jochiwon', 'senangku', 'dutchgaming', 'hiranai', 'chairsy', 'genelotrics', 'bahemas', 'gameniture', 'martenkaiser', 'secretracer']
web_data_non_ful = ['0', '5.13', '0', '0', '0.00', '0.00', '0', '0', '6.25', '0.58', '0', '0', '0.00']
web_data_late_ship = ['0', '8.89', '0', '0', '8.33', '0.00', '0', '0', '0', '1.51', '0', '0', '0.00']
web_data_pre_time = ['0', '1.50', '2.02', '1.49', '2.17', '0.93', '2.04', '0.94', '1.30', '1.77', '', '', '1.07']
web_data_resp_rate = ['57.00', '96.01', '95.45', '100.00', '98.26', '98.32', '92.97', '91.05', '98.70', '97.44', '100.00', '57.00', '97.04']
web_data_shop_rate = ['0', '4.85', '5.00', '5.00', '4.70', '4.78', '4.89', '4.74', '4.88', '4.74', '5.00', '0', '4.71']
web_data_penal_points = ['0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', '0']

def sheet_updater(shop_names, col_num, col_data):
    values = []
    for cn, cd in zip(col_num, col_data):
        try:
            temp = []
            r = 2
            x = 0
            for i in range(13):
                try:
                    temp.append(cd[x])
                    r += 1
                except:
                    pass
                x += 1
            values.append(temp)
        except:
            pass
    return [list(x) for x in zip(*values)]

col_data = [shop_names, web_data_non_ful, web_data_late_ship,web_data_pre_time, web_data_resp_rate, web_data_shop_rate, web_data_penal_points]
col_num = [1, 2, 3, 4, 5, 6, 7]
res = sheet_updater('sheet1', col_num, col_data)
sheet.update('A1', res, value_input_option='USER_ENTERED')
  • In this modification, the values are put to a list, and the list is put to the Spreadsheet using Sheets API. By this flow, the values are put into the Spreadsheet by one API call. By this, I thought that your issue can be removed.

Reference:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文