1

Help me please. When starting a program that outputs data from google sheets, an error appears.

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()

Error:

googleapiclient.errors.HttpError: <HttpError 403 when requesting (link) returned "Rate limit exceeded. User message: "Sorry, you have exceeded your sharing quota."". Details: "[{'domain': 'global', 'reason': 'sharingRateLimitExceeded', 'message': 'Rate limit exceeded. User message: "Sorry, you have exceeded your sharing quota."'}]">

eglease
  • 2,445
  • 11
  • 18
  • 28

2 Answers2

0

The error states that you usage limit has been exceed.

This version of the Google Sheets API has a limit of 500 requests per 100 seconds per project, and 100 requests per 100 seconds per user. Limits for reads and writes are tracked separately. There is no daily usage limit.

To view or change usage limits for your project, or to request an increase to your quota, do the following:

If you don't already have a billing account for your project, then create one. Visit the Enabled APIs page of the API library in the API Console, and select an API from the list. To view and change quota-related settings, select Quotas. To view usage statistics, select Usage.

You might need to pay more to get a higher usage quota.

eglease
  • 2,445
  • 11
  • 18
  • 28
0

Hallo this question is duplicate and has an answer here. Setting the send NotificationEmail=False is what solved the problem. For example:

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