iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.

Home Page:https://docs.iterative.ai/PyDrive2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The user has exceeded their Drive storage quota

meet1919 opened this issue · comments

I am using service account for automating drive uploads. Earlier so many files were getting uploaded in the daily basis and eveything worked but now I am seeing this error.

pydrive2.files.ApiRequestError: <HttpError 403 when requesting None returned "The user has exceeded their Drive storage quota". Details: "[{'domain': 'usageLimits', 'reason': 'quotaExceeded', 'message': 'The user has exceeded their Drive storage quota'}]">

Does each individual user who has access to the same account have their respective quota of storage? Currently, the file which is uploaded via PyDrive2 are owned by the service account (in the file details it shows that they are created by the service account). In the drive currently, only 400kb is used and all the 15GB is free. What is the reason for this error?

Also when deleting any file or folder from the drive UI (which has been uploaded/created by the service account) gets deleted permanently rather than moving to trash/bin.

hey @meet1919 , it might the same issue as described here iterative/dvc.org#3963 . Service accounts (unless delegation is enabled) have indeed their own (default?) limits.

Also when deleting any file or folder from the drive UI (which has been uploaded/created by the service account) gets deleted permanently rather than moving to trash/bin.

probably the same reason. They are moved to the service accounts trash? (i'm not 100% sure).

@shcheklein is there any work around for this? I mean without using delegations?

@shcheklein Hey, is it possible to transfer/change ownership (to the user whose drive the service account is using) automatically when a file is uploaded from the service account? like passing specific user name or permissionId when creating file

drive.CreateFile({'parents': [{'id': parent_folder_id}], 'title': filename, 'permissionId': 'permission id of the user to which ownership must be transferred'})

I tried this:

file1 = drive.CreateFile({'id': 'id of the file whose owner is service account'})
file1.Upload()

# Insert the permission.
permission = file1.InsertPermission({
                        'type': 'user',
                        'value': 'email of the drive owner',
                        'role': 'owner',
                        'id': 'permission id of the above email'})

print(file1['alternateLink']) 

I got an error :

pydrive2.files.ApiRequestError: <HttpError 403 when requesting 
https://www.googleapis.com/drive/v2/files/1Q0WBmLyoGuBbwbfy-9Mdj6OH_c_05n4_/permissions?
supportsAllDrives=true&alt=json returned "Consent is required to transfer ownership of a file to another user.". Details: "
[{'message': 'Consent is required to transfer ownership of a file to another user.', 'domain': 'global', 'reason': 
'consentRequiredForOwnershipTransfer'}]">

where do I give this consent?

If you try to change owner using the UI, it will send a mail to the new owner asking to accept the ownership of the file.
image
image

I suppose the error is related to this.

If you find a way to transfer ownership bypassing the email confirmation via API, please let me know!

The only other method I know to transfer ownership of a file is to copy it. If a file is copied, the copy is owned by the user that copied it.

hey @meet1919 , it might the same issue as described here iterative/dvc.org#3963 . Service accounts (unless delegation is enabled) have indeed their own (default?) limits.

Also when deleting any file or folder from the drive UI (which has been uploaded/created by the service account) gets deleted permanently rather than moving to trash/bin.

probably the same reason. They are moved to the service accounts trash? (i'm not 100% sure).

@shcheklein I created a google workspace/admin account and authorized the service account to impersonate a user. I used that service account to upload file to the drive of that user but still the drive uploads to the storage space of the service account rather than the storage space for the user. As described here iterative/dvc.org#3963

Google service accounts have upload/download limits (which are quite low - at least by standard). If these limits are exceeded pushing/pulling experiments to the remote throws a 403 http error 'The user has exceeded their Drive storage quota'. This issue can be fixed with delegation and setting gdrive_service_account_user_email to be the user email (not service account email) as proposed by @shcheklein.

What is this: gdrive_service_account_user_email and where should I configure it in PyDrive2 ?

commented

This problem is solved. If service account is used in a Google workspace account than this is how service account can impersonate the gsuite user account.

from pydrive2.auth import GoogleAuth
from oauth2client.service_account import ServiceAccountCredentials

scope = ["https://www.googleapis.com/auth/drive"]
gauth = GoogleAuth()
gauth.auth_method = 'service'
gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name('client_secrets_service.json', scope).create_delegated('xyz@yourdomain')