python - 请求时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."'}]">
解决方案
你好,这个问题是重复的,在这里有答案。设置 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()
推荐阅读
- c# - 为什么 CLR 为每个方法分配一个包含一个条目的内部结构
- python - 使用 Pandas DataFrame 向现有 CSV 添加新行
- powershell - powershell浏览到文件路径
- python - 在 python 列表理解中获取索引值(在前面有变量)
- django - 反向外键模型形式
- c - 带回车符的 C 程序 \r
- javascript - 在 onclick javascript 效果之后,我可以在 css 中定位一个 :hover 函数吗?
- c# - 获取数组中的最高数字,然后在该数组中添加一个新值并使用前面的 +1 不起作用 - C#
- sql - 将 2 个单独列的总和与 SQL 语句进行比较
- python - matplotlib 中的多行动画