From 270a76c40bac81dc75d4ba2df27633f9c0dfa0ad Mon Sep 17 00:00:00 2001 From: Harmon Date: Tue, 12 Jan 2021 15:35:42 -0600 Subject: [PATCH] Remove max file size checks for chunked uploads The error messages Twitter's API responds with when the file size is too large, "File size exceeds 15728640 bytes." for GIFs and "File size exceeds 536870912 bytes." for videos, are fairly self-explanatory. This check was incorrect for videos anyway, which seem to have a size restriction of 512 MiB, not 15 MB. https://developer.twitter.com/en/docs/twitter-api/v1/media/upload-media/uploading-media/media-best-practices https://twittercommunity.com/t/conflicting-documented-size-restrictions-for-video-uploading-via-api/148201 Allowing Twitter's API to handle the size restrictions and avoiding hardcoding them also removes the need to update them in the future if they change. --- tweepy/api.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 4ed42d1..b1b0e2a 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -22,7 +22,6 @@ MAX_CHUNKSIZE = 5 * 1024 MIN_CHUNKSIZE = 16 MAX_UPLOAD_SIZE_STANDARD = 4883 # standard uploads must be less than 5 MB -MAX_UPLOAD_SIZE_CHUNKED = 14649 # chunked uploads must be less than 15 MB class API: @@ -241,8 +240,6 @@ class API: if file_type not in IMAGE_TYPES and file_type not in CHUNKED_TYPES: raise TweepError(f'unsupported media type: {file_type}') - if size_bytes > MAX_UPLOAD_SIZE_CHUNKED * 1024: - raise TweepError(f'Media files must be smaller than {MAX_UPLOAD_SIZE_CHUNKED} kb') if file_type in IMAGE_TYPES and size_bytes < MAX_UPLOAD_SIZE_STANDARD * 1024: return self.simple_upload(filename, file=file, *args, **kwargs) @@ -275,16 +272,11 @@ class API: # Media category is dependant on whether media is attached to a tweet # or to a direct message. Assume tweet by default. - # Initialize upload (Twitter cannot handle videos > 15 MB) - fp = file or open(filename, 'rb') fp.seek(0, 2) # Seek to end of file file_size = fp.tell() - if file_size > (MAX_UPLOAD_SIZE_CHUNKED * 1024): - raise TweepError(f'File is too big, must be less than {MAX_UPLOAD_SIZE_CHUNKED} KiB.') - fp.seek(0) # Reset to beginning of file media_id = self.chunked_upload_init( -- 2.25.1