首页 > 解决方案 > 请求时Google Sheets HttpError 403

问题描述

请帮帮我。启动从 google 表格输出数据的程序时,会出现错误。

import httplib2
import apiclient.discovery
from oauth2client.service_account import ServiceAccountCredentials

# Работа с таблицами
CREDENTIALS_FILE = 'file_name.json' 
credentials = ServiceAccountCredentials.from_json_keyfile_name(CREDENTIALS_FILE, ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'])
httpAuth = credentials.authorize(httplib2.Http())
service = apiclient.discovery.build('sheets', 'v4', http = httpAuth) # Выбираем работу с таблицами и 4 версию API


spreadsheetId = '1oXzqYQ9HixjfkTJ7hmIVqrM7_uvYwPsHoEKqPdbaAgk' 

driveService = apiclient.discovery.build('drive', 'v3', http = httpAuth) 
access = driveService.permissions().create(
    fileId = spreadsheetId,
    body = {'type': 'user', 'role': 'writer', 'emailAddress': 'account@requests-329915.iam.gserviceaccount.com'},  
    fields = 'id'
).execute()

错误:

googleapiclient.errors.HttpError: <HttpError 403 when requesting (link) 返回“超出速率限制。用户消息:“抱歉,您已超出共享配额。”。详细信息:“[{'domain': 'global', 'reason': 'sharingRateLimitExceeded', 'message': 'Rate limit exceeded. User message: "Sorry, you have exceeded your share quota."'}]">

标签: pythongoogle-sheetsoauth-2.0http-status-code-403

解决方案


你好,这个问题是重复的,在这里有答案。设置 send NotificationEmail=False 是解决问题的方法。例如:

access = driveService.permissions().create(
    fileId = spreadsheetId,
    body = {'type': 'user', 'role': 'writer', 'emailAddress': 'account@requests-329915.iam.gserviceaccount.com'},  
    fields = 'id',
    sendNotificationEmail=False
).execute()

推荐阅读