From: Harmon Date: Fri, 19 Feb 2021 23:07:52 +0000 (-0600) Subject: Specify file kwarg for API.media_upload explicitly X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6a8783c2cde0b360335e32c6da12a07ba1af50d1;p=tweepy.git Specify file kwarg for API.media_upload explicitly --- diff --git a/tweepy/api.py b/tweepy/api.py index 5497ffe..e09f7b8 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -334,16 +334,14 @@ class API: ) @payload('media') - def media_upload(self, filename, *args, **kwargs): + def media_upload(self, filename, *args, file=None, **kwargs): """ :reference: https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload """ - f = kwargs.pop('file', None) - h = None - if f is not None: - location = f.tell() - h = f.read(32) - f.seek(location) + if file is not None: + location = file.tell() + h = file.read(32) + file.seek(location) file_type = imghdr.what(filename, h=h) or mimetypes.guess_type(filename)[0] if file_type == 'gif': max_size = 14649 @@ -351,7 +349,7 @@ class API: max_size = 4883 headers, post_data = API._pack_image(filename, max_size, - form_field='media', f=f, + form_field='media', f=file, file_type=file_type) kwargs.update({'headers': headers, 'post_data': post_data})