Use proper MIME type in Content-Type header for uploaded images
authorHarmon <Harmon758@gmail.com>
Sun, 2 Aug 2020 20:00:37 +0000 (15:00 -0500)
committerHarmon <Harmon758@gmail.com>
Sun, 2 Aug 2020 20:01:17 +0000 (15:01 -0500)
Fixes regression introduced with #1086 where Content-Type headers of uploaded images did not use proper MIME type structure and only specified the subtype

tweepy/api.py

index ba047d34e8c5fa0fcc3c8283ef334f119ba38f60..4a2599c76ff3c653b200271c81d0b9912d0d81d3 100644 (file)
@@ -1421,7 +1421,9 @@ class API(object):
             file_type = imghdr.what(filename) or mimetypes.guess_type(filename)[0]
         if file_type is None:
             raise TweepError('Could not determine file type')
-        if file_type not in ['gif', 'jpeg', 'png', 'webp', 'image/gif', 'image/jpeg', 'image/png']:
+        if file_type in ['gif', 'jpeg', 'png', 'webp']:
+            file_type = 'image/' + file_type
+        elif file_type not in ['image/gif', 'image/jpeg', 'image/png']:
             raise TweepError('Invalid file type for image: %s' % file_type)
 
         if isinstance(filename, six.text_type):