Overview
The TikTok API module provides a hierarchy of exception classes to handle different error scenarios. All exceptions inherit from the baseTikTokError class, allowing you to catch all TikTok-related errors with a single exception handler.
Exception Hierarchy
Exception Classes
TikTokError
Base exception for all TikTok API errors.TikTokDeletedError
Raised when a video has been deleted by the creator or removed by TikTok.- Video returns status code 10204 (not found)
- Video returns status code 10216 (under review)
- yt-dlp returns “unavailable”, “removed”, or “deleted” error
TikTokPrivateError
Raised when a video is private and cannot be accessed.- Video returns status code 10222 (private)
- yt-dlp returns “private” error
TikTokNetworkError
Raised when a network error occurs during the request.- Media download fails after all retry attempts
- Connection timeout
- CDN returns persistent errors (403, 500, 502, 503, 504)
TikTokRateLimitError
Raised when too many requests have been made and TikTok is rate limiting.- yt-dlp returns “rate”, “too many”, or “429” error
- TikTok API returns rate limit response
- Use proxy rotation to distribute requests across IPs
- Add delays between requests
- Use cookies from authenticated sessions (higher rate limits)
TikTokRegionError
Raised when a video is not available in the user’s region (geo-blocked).- Video is geo-restricted
- yt-dlp returns “region”, “geo”, “country”, or “not available in your” error
- Use proxies from regions where the video is available
- Some videos are only available in specific countries
TikTokExtractionError
Raised when extraction/parsing fails for unknown reasons.- yt-dlp extraction fails
- Invalid video ID
- TikTok page structure changed
- Incompatible yt-dlp version
- No video data returned
- Update yt-dlp:
pip install -U yt-dlp - Check if TikTok changed their page structure
- Verify the URL is valid
- Check yt-dlp GitHub issues
TikTokVideoTooLongError
Raised when a video exceeds the maximum allowed duration.- Video duration exceeds configured maximum (if max_duration is set in config)
TikTokInvalidLinkError
Raised when a TikTok link is invalid or expired.- URL doesn’t match any known TikTok URL pattern
- Short URL resolution fails after all retries
- URL redirects to unexpected domain
Error Handling Patterns
Basic Error Handling
Handle all TikTok errors uniformly:Granular Error Handling
Handle specific errors differently:Retry with Different Proxy
Handle transient errors by retrying with a different proxy:User-Friendly Error Messages
Provide clear messages to end users:Logging Errors
Log errors for debugging while showing user-friendly messages:Best Practices
- Always catch TikTokError - Use the base exception to catch all TikTok-related errors
- Handle permanent vs transient errors - Don’t retry deleted/private/region errors
- Use proxy rotation - Handle rate limits and network errors by rotating proxies
- Provide user feedback - Convert exceptions to user-friendly messages
- Log for debugging - Keep detailed logs while showing simple messages to users
- Update yt-dlp regularly - Many extraction errors are fixed by updating yt-dlp
- Use cookies for authentication - Reduces rate limiting and allows access to more content

