From: Yechiel K Date: Thu, 2 Jul 2020 00:00:05 +0000 (-0400) Subject: add file_type as keyword arg in API._pack_image X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=af3239245eed4ce039c190a3f1273c4a21c4cf8c;p=tweepy.git add file_type as keyword arg in API._pack_image --- diff --git a/tweepy/api.py b/tweepy/api.py index b7b757b..60affc3 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -227,7 +227,8 @@ class API(object): max_size = 4883 headers, post_data = API._pack_image(filename, max_size, - form_field='media', f=f) + form_field='media', f=f, + file_type=file_type) kwargs.update({'headers': headers, 'post_data': post_data}) return bind_api( @@ -1363,7 +1364,7 @@ class API(object): """ Internal use only """ @staticmethod - def _pack_image(filename, max_size, form_field='image', f=None): + def _pack_image(filename, max_size, form_field='image', f=None, file_type=None): """Pack image from file into multipart-formdata post body""" # image must be less than 700kb in size if f is None: @@ -1385,7 +1386,8 @@ class API(object): fp = f # image must be gif, jpeg, png, webp - file_type = imghdr.what(filename) + if not file_type: + file_type = imghdr.what(filename) if file_type is None: raise TweepError('Could not determine file type') if file_type not in ['gif', 'jpeg', 'png', 'webp']: