From a26746ce0bdb16ec0e66a1bc10d1570c886763ac Mon Sep 17 00:00:00 2001 From: Harmon Date: Wed, 13 Jan 2021 10:18:07 -0600 Subject: [PATCH] Remove file type check in API.media_upload The error message Twitter's API responds with when the file type is unsupported, "media type unrecognized.", is fairly self-explanatory. Allowing Twitter's API to handle the media type check and avoiding hardcoding supported types also removes the need to update them in the future if they change. --- tweepy/api.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 3eb1be4..6cf3c03 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -12,7 +12,6 @@ from tweepy.parsers import ModelParser, Parser, RawParser from tweepy.utils import list_to_csv IMAGE_TYPES = ['gif', 'jpeg', 'png', 'webp'] -CHUNKED_TYPES = IMAGE_TYPES + ['video/mp4'] MAX_UPLOAD_SIZE_STANDARD = 4883 # standard uploads must be less than 5 MB @@ -231,9 +230,6 @@ class API: size_bytes = os.path.getsize(filename) file_type = imghdr.what(filename, h=h) or mimetypes.guess_type(filename)[0] - if file_type not in IMAGE_TYPES and file_type not in CHUNKED_TYPES: - raise TweepError(f'unsupported media type: {file_type}') - if file_type in IMAGE_TYPES and size_bytes < MAX_UPLOAD_SIZE_STANDARD * 1024: return self.simple_upload(filename, file=file, *args, **kwargs) else: -- 2.25.1