因此,我在Google Cloud Compute engine中设置了一个python脚本,该脚本设置为在一天中使用cron选项卡定期运行。但是最近,脚本返回了这个错误,
gspread.exceptions.APIError:{‘代码’:429,‘消息’:“超出了服务'sheets.googleapis.com‘for consumer’项目的配额指标'Read requests‘和limit 'Read requests per user’的配额_编号:583704109550‘.“,’状态‘:’资源_耗尽‘,’详细信息‘:
{'@type':'type.googleapis.com/google.rpc.ErrorInfo',‘原因’:‘费率_限制_已超出‘,’域‘:'googleapis.com',’元数据‘:{’配额_指标‘:'sheets.googleapis.com/read_请求‘,’配额_limit':'ReadRequestsPerMinutePerUser','service':'sheets.googleapis.com','consumer':'projects/583704109550'}}}
我试图研究为什么它会抛出它,但由于我在该领域的经验不足,我感到困惑。这是任何人都想知道的脚本,
from woocommerce import API
from df2gspread import df2gspread as d2g
from df2gspread import gspread2df as g2d
from collections import defaultdict
import pandas as pd
import gspread
from oauth2client.service_account import ServiceAccountCredentials
def parseData(entry):
#Extract relectant information (all key value pairs that are listed under meta_data)
d = {pair["key"]:pair["value"] for pair in entry["line_items"][0]["meta_data"]}
d["Event"] = entry["line_items"][0]["name"]
return d
wcapi = API(
url="REDACTED",
consumer_key="REDACTED",
consumer_secret="REDACTED",
version="wc/v3",
query_string_auth="true"
)
entries = []
pageNum = 1
while True:
#API is paginated with products per page limit of 100
rawEntries = wcapi.get("orders", params = {"per_page": 100, "page": pageNum}).json()
#Page until there are no entries on a page
if len(rawEntries) == 0:
break
entries.extend([parseData(e) for e in rawEntries])
pageNum += 1
rawEvents = defaultdict(list)
for entry in entries:
#Organize entries by their event
rawEvents[entry["Event"]].append(entry)
events = {k: pd.DataFrame(v).fillna('') for (k,v) in rawEvents.items()} #Built a dataframe for each event
#Upload to Google Sheets using gspread and df2gspread
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('/home/shahav2016/GoogleKeyJSON.json', scope)
gc = gspread.authorize(credentials)
spreadsheet_key = 'REDACTED FOR PRIVACY REASONS' #The name of the spreadsheet - look at the URL
for event, df in events.items():
#Filter out test events
if event not in ['REDACTED FOR PRIVACY']:
#Upload the data to the correct sheet
d2g.upload(df, spreadsheet_key, event, row_names = False, credentials = credentials)
发布于 2020-12-05 10:53:41
Google Sheets API对每100秒可以处理的请求数有限制。这是来自文档表接口v4的页面。
此版本的Google Sheets API的限制为每个项目每100秒500个请求,每个用户每100秒100个请求。对读取和写入的限制是单独跟踪的。没有每日使用限制。
要查看或更改项目的使用限制,或请求增加配额,请执行以下操作:
如果你的项目还没有帐单账户,那就创建一个。在API控制台访问API库的已开通API页面,从列表中选择API。要查看和更改与配额相关的设置,请选择配额。要查看使用率统计信息,请选择使用率。
此外,有三个选项可以绕过此限制:
https://stackoverflow.com/questions/65153922
复制相似问题