Image type bug fixes
authorkeatonconrad <keaton.conrad@gmail.com>
Wed, 16 Dec 2020 04:43:54 +0000 (22:43 -0600)
committerkeatonconrad <keaton.conrad@gmail.com>
Wed, 16 Dec 2020 04:43:54 +0000 (22:43 -0600)
tweepy/api.py

index 1bb16e0ad1f53be96d3525144f7cda98cbe6f825..b426d796454e228aa5d0b05fbb3b376e7e7c2ed3 100644 (file)
@@ -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']: