Overview
Platzi Viewer relies entirely on Google Drive API to stream course content. This page covers common Drive API errors and how to resolve them.Authentication Errors
Drive service not available (503)
Drive service not available (503)
Error Message:Check health endpoint:Response:Causes and solutions:1. Service account file not found:The server searches for 2. Invalid JSON format:Error detail: Common issues:How to get the correct file:
service_account.json in:- Path specified in
GOOGLE_SERVICE_ACCOUNT_FILEenvironment variable - Executable directory (for .exe builds)
- Current working directory
- Script directory
"GOOGLE_SERVICE_ACCOUNT_JSON is not valid JSON"Verify the JSON file is valid:- Missing commas
- Trailing commas (not allowed in JSON)
- Unescaped quotes in strings
- UTF-8 BOM (byte order mark) at start of file
- Go to Google Cloud Console
- Select your project
- Navigate to IAM & Admin > Service Accounts
- Click on your service account
- Go to Keys tab
- Click Add Key > Create new key
- Select JSON format
- Download and save as
service_account.json
Using environment variable for credentials (Docker)
Using environment variable for credentials (Docker)
For Docker or environments where file mounting is difficult:Pass the entire JSON as an environment variable:In docker-compose.yml:In .env file (for docker-compose):
Permission denied on shared Drive folder
Permission denied on shared Drive folder
Token refresh errors
Token refresh errors
Error Message:Usually harmless - the server will refresh tokens automatically on first API call.If persistent:
- Check your system clock is correct (token validation is time-sensitive)
- Verify internet connectivity
- Regenerate service account key if very old (keys don’t expire, but can be revoked)
API Rate Limiting and Quotas
Drive API quota exceeded
Drive API quota exceeded
Symptom: Errors during cache rebuild or file streaming after heavy usage.Google Drive API quotas for service accounts:If regularly hitting limits:
- Queries per minute: 12,000
- Queries per day: 1,000,000,000 (effectively unlimited)
- Go to Google Cloud Console
- Navigate to APIs & Services > Dashboard
- Click on Google Drive API
- View Quotas tab
rebuild_cache_drive.py:- The script includes automatic throttling (~100 calls/second max)
- Built-in retry logic with exponential backoff
- Progress is saved in
drive_scan_progress.jsonso you can resume
- Reduce scan frequency
- Cache the results (don’t rebuild unnecessarily)
- Request quota increase in Google Cloud Console
Rate limiting during video streaming
Rate limiting during video streaming
Symptom: Videos buffer excessively or fail to load during peak usage.Monitoring:
Check server logs for:Built-in mitigations:
- Server uses retry logic with exponential backoff (up to 5 retries)
- Shared authentication session to reduce token refresh overhead
- HTTP Range Request support minimizes data transfer
-
Reduce concurrent streams:
- Don’t open multiple videos simultaneously
- Close unused browser tabs
-
Increase request quota (if you own the project):
- Request quota increase
- Select Drive API v3
- Request increase for relevant metrics
-
Use caching proxy (advanced):
- Set up nginx or similar to cache Drive responses
- Reduces duplicate requests for same content
File Access Errors
Invalid file ID (400)
Invalid file ID (400)
Error Message:Causes:Response:
-
Local file reference (migration issue):
Solution: The cache was built with an older version that used local files. Rebuild:
-
Malformed Drive ID:
- Valid Drive IDs match regex:
[A-Za-z0-9_-]{10,} - Must be at least 10 characters
- Only alphanumeric, underscore, and hyphen allowed
- Valid Drive IDs match regex:
-
Cache corruption:
- Delete
courses_cache.jsonand rebuild
- Delete
File not found (404)
File not found (404)
Symptom: A course or class shows in the UI but videos/files won’t load.Possible causes:
-
File was deleted from Drive:
- Verify the file exists in Google Drive web interface
- If deleted, rebuild cache to remove stale references
-
File is in trash:
- Files in Drive trash are excluded from listings
- Restore the file or permanently delete and rebuild cache
-
Cache is outdated:
- Drive folder structure changed since last cache build
- Rebuild:
-
Service account lost access:
- Folder sharing was revoked
- Re-share the folder with the service account email
MIME type detection errors
MIME type detection errors
Symptom: Files download instead of playing/displaying inline.Cause: Google Drive sometimes returns If a file type is not recognized:
application/octet-stream for known file types.Automatic fallback:
The server includes MIME type detection by file extension as a fallback.File type mappings in server.py:- It will be served as
application/octet-stream - Browser will likely download it instead of displaying it
- This is expected behavior for unknown types
Drive API Internal Errors
500 Internal Server Error from Drive
500 Internal Server Error from Drive
Error in server logs:Cause: Google Drive API occasionally returns transient 500 errors.Automatic mitigation:
drive_service.pyincludes retry logic with exponential backoff- Up to 5 retries with delays: 2s, 4s, 8s, 16s, 32s
- Most 500 errors resolve on retry
- Check Google Workspace Status Dashboard
- Wait for Google to resolve the issue
- If urgent, try again in 10-30 minutes
Backend disconnection / broken pipe errors
Backend disconnection / broken pipe errors
Log patterns:Common causes:
-
Client closed connection:
- User navigated away from page
- Browser stopped the request
- Not an error - the server detects this and doesn’t log it
-
Network interruption:
- WiFi disconnection
- VPN timeout
- ISP issues
- Solution: Retry the request or check network stability
-
Drive API timeout:
- Very large files or slow Drive response
- Server timeout is 60s for streaming (
timeout=(5, 60)) - If file is extremely large, consider downloading separately
SSL/TLS certificate errors
SSL/TLS certificate errors
Error Message:Causes:
-
System clock is wrong:
- Certificate validation is time-sensitive
- Sync your system clock
-
Outdated CA certificates:
-
Corporate proxy or firewall:
- Proxy is intercepting HTTPS traffic
- May need to install corporate CA certificate
- Or configure proxy settings:
Progress and Metadata Endpoints
Progress save fails (413 Payload Too Large)
Progress save fails (413 Payload Too Large)
Error Response:Default limit: 2MB (Why so large?
MAX_PROGRESS_BYTES=2097152)Solution:- Progress is stored as a JSON object with keys for every class
- Large course catalogs can result in >1MB of progress data
- The limit prevents abuse/DoS attacks
Cache metadata endpoint returns null values
Cache metadata endpoint returns null values
Request:Response with null mtime:Cause: Cache file exists but couldn’t be stat’d (permissions or file system issue).Check:
Debugging Tools
Health Endpoint
drive.available- Should betruedrive.error- Should benullffmpeg.available- Needed for compatibility mode
Self-Check Endpoint
- All file references in cache are valid Drive IDs
- No local file references (
local:...) - No malformed IDs
ok: true- All references are validok: false- Issues found, checkissuesarray- Rebuild cache if
localRefs > 0orinvalidRefs > 0
Manual Drive API Test
Test authentication:- Environment variable differences between shells
- Python virtual environment not activated
- Different working directories
Docker-Specific Issues
Drive authentication in Docker container
Drive authentication in Docker container
Problem: Works locally but not in Docker.Checklist:
-
Volume mount is correct:
-
Environment variable points to mounted path:
Not
./service_account.jsonor relative paths. -
File exists in container:
-
Permissions are readable:
Should print JSON content (or at least not “Permission denied”).
See Also
- Common Issues - General troubleshooting
- Video Synchronization - A/V sync and FFmpeg issues
- Google Drive Setup - Setting up service accounts
- Installation Guide - Environment configuration