Specify file kwarg for API.media_upload explicitly
authorHarmon <Harmon758@gmail.com>
Fri, 19 Feb 2021 23:07:52 +0000 (17:07 -0600)
committerHarmon <Harmon758@gmail.com>
Fri, 19 Feb 2021 23:07:52 +0000 (17:07 -0600)
tweepy/api.py

index 5497ffe426a9c6829c022eae24828eb5cd25466c..e09f7b832ba270a92fe6dfc8b89ab5001297d7fa 100644 (file)
@@ -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})