【发布时间】:2021-10-02 13:26:28
【问题描述】:
运行下面的代码时,我收到以下错误“RATE_LIMIT_EXCEEDED”。我添加了一些延迟,但不确定我还能做些什么来纠正这个问题。有谁知道如何解决这个问题?
> Exception has occurred: HttpError <HttpError 429 when requesting
> https://sheets.googleapis.com/v4/spreadsheets/1FJiVwQu2AAca06dpkoh20zQYGyyQ8RBZJ8xWZgGlcS4/values/form%20%20-%20v1.01%211%3A200?alt=json
> returned "Quota exceeded for quota metric 'Read requests' and limit
> 'Read requests per minute per user' of service 'sheets.googleapis.com'
> for consumer 'project_number:1010550314584'.". Details: "[{'@type':
> 'type.googleapis.com/google.rpc.ErrorInfo', 'reason':
> 'RATE_LIMIT_EXCEEDED', 'domain': 'googleapis.com', 'metadata':
> {'quota_metric': 'sheets.googleapis.com/read_requests', 'consumer':
> 'projects/1010550314584', 'quota_limit':
> 'ReadRequestsPerMinutePerUser', 'service':
> 'sheets.googleapis.com'}}]"> File
> "OEE.py", line 43, in
> fetch_data_from_google_spreadsheet
> range=RANGE_NAME).execute()) File "Forge.py", line 43, in <module>
> forge_OEE = OEE.fetch_data_from_google_spreadsheet('blhalblahblha',google_credentials=creds)
# gets data from google spreadsheet
def fetch_data_from_google_spreadsheet(SPREADSHEET_ID, google_credentials):
# looks at connecting to the google api service
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
service = build('sheets', 'v4', credentials=google_credentials)
# Call the Sheets API
sheet = service.spreadsheets()
# Returns all sheets (tabs) in a spread sheet
time.sleep(3)
return_sheet_ID = sheet.get(spreadsheetId=SPREADSHEET_ID, ranges=None, includeGridData=None, x__xgafv=None).execute()
# extracts just the sheets
individual_sheets = return_sheet_ID.get("sheets")
list_of_dict_sheets = []
# loops through each tab and returns the rows within each sheet
for item in individual_sheets:
# returns the sheet names to pass into sheet values
RANGE_NAME = item.get("properties").get("title") + "!" + "1" + ":" + str(item.get("properties").get("gridProperties").get("rowCount"))
time.sleep(3)
# returns the rows within the spreadsheets
list_of_dict_sheets.append (sheet.values().get(spreadsheetId=SPREADSHEET_ID,
range=RANGE_NAME).execute())
df2 = None
# loops through each sheet and returns the details
for each_sheet in list_of_dict_sheets:
df = pd.DataFrame(each_sheet.get("values"))
df = df.rename(columns=df.iloc[0])
df = df.iloc[1:]
df2 = pd.concat([df,df2])
return df2
【问题讨论】:
标签: python google-api google-sheets-api google-api-python-client