google-drive-apiuploadstorage

google drive API failed and returned "HttpError 403: Service Accounts do not have storage quota"


dear all:

I am using google drive service account (as an editor) to share some files via google drive API. Everything worked fine. Then after one day, google drive returned error message 403 and said that I have no storage quota.
Then I created a new service account and upload files as an owner.
Everything worked fine again.
Then today while I was uploading files, the same error message 403 was returned again and again. But I checked my google drive and it only used less than 50K.

My code is the following.

        query = f"'{dirId}' in parents and name = '{fName}' and trashed = false"
        # checking already-existing files. 
        response = self.__service.files().list(
            q=query, 
            corpora="user", 
            fields="files(id, name, createdTime, modifiedTime, modifiedByMeTime, viewedByMeTime)"
        ).execute()
        # If find old files with the same names, delete them.
        for gFile in response.get('files', []):
            gFileId = gFile.get('id')
            gFileName = gFile.get('name')
            self.__service.files().update(removeParents=dirId, fileId=gFileId).execute()
            print(f"Deleted files with the same name from Google Drive: {fPath}/{gFileName} (ID: {gFileId})")

        # Now upload the file with same name. 
        fileMetadata = { 'name': fName, 'parents': [dirId] }
        media = MediaFileUpload(fPath, resumable=True)
        try: 
            uploaded_file = self.__service.files().create(
                body=fileMetadata,
                media_body=media,
                fields='id',
                supportsAllDrives=True
            ).execute()
            print(f"Done uploading {fPath}*{fName}, ID: {uploaded_file.get('id')}")
        except Exception as ex: 
            TestDragonCommons.printEx(ex, "???")
            print ("^^^")

The error message is the following.

<HttpError 403 when requesting None returned "Service Accounts do not have storage quota. Leverage shared drives (https://developers.google.com/workspace/drive/api/guides/about-shareddrives), or use OAuth delegation (http://support.google.com/a/answer/7281227) instead.". Details: "[{'message': 'Service Accounts do not have storage quota. Leverage shared drives (https://developers.google.com/workspace/drive/api/guides/about-shareddrives), or use OAuth delegation (http://support.google.com/a/answer/7281227) instead.', 'domain': 'usageLimits', 'reason': 'storageQuotaExceeded'}]">

Any help and comments will be highly appreciated.

Farn


Solution

  • Newly created accounts can't add comments, so I'm writing in the reply form. I ran into the same problem about 10 days ago. Just a regular Google account, not a workspace, was registered a long time ago, and an error about lack of space began to appear. After receiving additional information via Google Drive API, I saw that storageQuota.limit = 0, while there is disk space on drive.google.com

    Part of the response: 'storageQuota': {'limit': '0', 'usage': '3040221', 'usageInDrive': '3040221', 'usageInDriveTrash': '0'}
    Service Accounts do not have storage quota. Leverage shared drives.