Service account cannot retrieve Drive storage quota information

I’m having trouble with my Google service account setup. When I try to check the storage quota using the Drive API, it returns 0.00 GB for all values (total, used, and free storage). But when I attempt to create a new spreadsheet, I get a 403 error saying the storage quota is exceeded.

from google.auth.transport.requests import Request
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

SCOPES = [
    'https://www.googleapis.com/auth/spreadsheets',
    'https://www.googleapis.com/auth/drive'
]

CREDENTIALS_PATH = 'auth/service_key.json'

# Initialize credentials
service_creds = service_account.Credentials.from_service_account_file(
    CREDENTIALS_PATH, 
    scopes=SCOPES
)

# Create drive service
drive_api = build('drive', 'v3', credentials=service_creds)

info = drive_api.about().get(fields="storageQuota, user").execute()
quota_info = info.get('storageQuota', {})

print("=== Quota Details ===")
if 'limit' in quota_info:
    total_limit = int(quota_info['limit'])
    current_usage = int(quota_info['usage'])
    print(f"Total: {total_limit / (1024**3):.2f} GB")
    print(f"Used: {current_usage / (1024**3):.2f} GB")
    print(f"Available: {(total_limit - current_usage) / (1024**3):.2f} GB")
else:
    print("Cannot determine storage limits")

Error when creating spreadsheet:

403 Error: The user's Drive storage quota has been exceeded

The actual Google Drive account has plenty of space remaining (around 50GB free). Why isn’t the service account accessing the correct storage information? How can I fix this issue?

I hit this exact same issue building a batch processing system for company docs. Your service account only gets 15GB of storage, which fills up fast when you’re creating multiple files. Domain-wide delegation fixes this, but you’ll need G Workspace admin access to set it up. Enable delegation in the admin console, then modify your code to impersonate a regular user instead of using the service account directly. You’ll tap into the user’s storage quota rather than being stuck with the service account’s tiny 15GB limit. Those zero values in your quota response? That’s normal - Google blocks service accounts from seeing quota info through the standard API. Can’t get admin access? Set up a cleanup routine that deletes temp files right after processing to stay under that 15GB cap.

Service accounts have their own separate 15GB storage limit - that’s why you’re getting zero values and 403 errors. It’s completely isolated from your personal Google Drive space. I hit this same wall last year building a document generator. The service account filled up fast with temp files and started throwing quota errors, even though we had terabytes in our workspace accounts. Here’s what fixed it: Clean up temp spreadsheets after processing them. If you need files to stick around, use domain-wide delegation to impersonate a user account instead of relying on the service account’s storage. The quota API returns zero because Google doesn’t expose service account quotas through normal Drive endpoints. They handle them differently behind the scenes.

yeah, sounds like ur service account is limited to its own 15GB. Best bet is to use OAuth2 or set up domain-wide delegation for accessing ur main Drive quota. hope that helps!

Had this exact problem last month! Service accounts get stuck with their own separate 15GB quota - it’s not your main drive space. Quick fix: delete old spreadsheets regularly or switch to impersonating a real user account with domain delegation if you’ve got admin rights.

The Problem:

You’re encountering a 403 Error: The user's Drive storage quota has been exceeded when using a Google service account to create spreadsheets, even though the associated Google Drive account has ample free space. The Drive API also reports zero storage usage for the service account.

:thinking: Understanding the “Why” (The Root Cause):

The issue is not a misconfiguration of your authentication or scopes. Google service accounts have their own, separate 15GB storage quota, completely independent from your personal or organization’s Google Drive storage. The Drive API call to get quota information will return zero because Google intentionally doesn’t expose service account quotas through the standard API endpoints. The 403 error indicates that this separate 15GB quota for your service account has been reached.

:gear: Step-by-Step Guide:

  1. Identify and Address the Service Account Quota: The root cause is that your service account’s isolated 15GB storage quota is full. To resolve this, you need to manage the files created by your service account. The most straightforward approach is to implement a cleanup process that deletes temporary files or spreadsheets immediately after they’ve been processed.

  2. Implement File Deletion (Example): Modify your Python code to delete the created spreadsheet after successful processing. Here’s how you can integrate file deletion using the Drive API. This assumes you know the fileId of the spreadsheet you just created. (Remember to handle potential errors appropriately.)

from google.auth.transport.requests import Request
from google.oauth2 import service_account
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

# ... your existing code ...

# After successful spreadsheet creation:

try:
    drive_api.files().delete(fileId=spreadsheet_file_id).execute()
    print("Temporary spreadsheet deleted successfully.")
except HttpError as error:
    print(f"An error occurred while deleting the spreadsheet: {error}")

  1. Consider Alternative Approaches (for larger scale): If the 15GB limit is frequently reached, even with cleanup, consider more robust solutions. These require more advanced setup:

    • Domain-Wide Delegation: This allows your service account to impersonate a regular user account, granting it access to the user’s much larger storage quota. However, this requires Google Workspace administrator privileges and careful configuration to manage user permissions effectively.
    • Using an Automation Platform: Consider using a third-party tool (as suggested in some of the original forum posts) that’s specifically designed for automating Google Drive tasks. These platforms often handle authentication, quota management, and error handling more efficiently.

:mag: Common Pitfalls & What to Check Next:

  • Incorrect File Deletion: Double-check your file deletion logic. Ensure that the fileId is correct and that you are handling potential HttpError exceptions gracefully. Log the errors to help diagnose issues if deletion fails.
  • Insufficient Permissions: Confirm that your service account has the necessary permissions (https://www.googleapis.com/auth/drive) to delete files in Google Drive.
  • Rate Limiting: While less likely the primary problem here, excessive API calls can trigger rate limits. If you’re deleting many files, add small delays using time.sleep() between operations.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.