【问题标题】:Google Sheets HttpError 403 when requesting请求时Google Sheets HttpError 403
【发布时间】:2021-12-10 09:51:50
【问题描述】:

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

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:

【问题讨论】:

    标签: python google-sheets oauth-2.0 http-status-code-403


    【解决方案1】:

    错误表明您的使用限制为exceed

    此版本的 Google Sheets API 限制每个项目每 100 秒 500 个请求,每个用户每 100 秒 100 个请求。单独跟踪读取和写入的限制。没有每日使用限制。

    要查看或更改项目的使用限制,或请求增加配额,请执行以下操作:

    如果您还没有项目的结算帐号,那么 创建一个。访问 API 中 API 库的 Enabled APIs 页面 控制台,然后从列表中选择一个 API。查看和更改 配额相关设置,选择配额。要查看使用统计信息, 选择用法。

    您可能需要支付更多费用才能获得更高的使用配额。

    【讨论】:

      【解决方案2】:

      你好,这个问题是重复的,答案是here。设置 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()
      

      【讨论】:

        猜你喜欢
        • 2021-12-02
        • 2012-10-26
        • 1970-01-01
        • 1970-01-01
        • 2016-11-21
        • 2017-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多