From 86f963c5acad2b6ffe25598f19c455b483e18de2 Mon Sep 17 00:00:00 2001 From: keatonconrad Date: Tue, 15 Dec 2020 22:43:54 -0600 Subject: [PATCH] Image type bug fixes --- tweepy/api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 1bb16e0..b426d79 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -221,7 +221,7 @@ class API(object): """ f = kwargs.pop('file', None) - file_type = imghdr.what(filename) or mimetypes.guess_type(filename)[0] + file_type = imghdr.what(filename, h=f.read()) or mimetypes.guess_type(filename)[0] if file_type == 'gif': max_size = 14649 else: @@ -828,7 +828,7 @@ class API(object): allowed_param=['cursor'], require_auth=True ) - + @property def mutes(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-list @@ -841,7 +841,7 @@ class API(object): allowed_param=['cursor', 'include_entities', 'skip_status'], required_auth=True ) - + @property def create_mute(self): @@ -1288,7 +1288,7 @@ class API(object): 'max_id', 'until', 'result_type', 'count', 'include_entities'] ) - + @pagination(mode='next') def search_30_day(self, environment_name, *args, **kwargs): """ :reference: https://developer.twitter.com/en/docs/tweets/search/api-reference/premium-search @@ -1303,7 +1303,7 @@ class API(object): 'next'], require_auth=True )(*args, **kwargs) - + @pagination(mode='next') def search_full_archive(self, environment_name, *args, **kwargs): """ :reference: https://developer.twitter.com/en/docs/tweets/search/api-reference/premium-search @@ -1418,7 +1418,7 @@ class API(object): # image must be gif, jpeg, png, webp if not file_type: - file_type = imghdr.what(filename, h=f) or mimetypes.guess_type(filename)[0] + file_type = imghdr.what(filename, h=f.read()) or mimetypes.guess_type(filename)[0] if file_type is None: raise TweepError('Could not determine file type') if file_type in ['gif', 'jpeg', 'png', 'webp']: -- 2.25.1