From 551a1d9e4f9ad89cbf5560ff64bca96446acc1c4 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Sun, 5 Aug 2018 03:42:15 +0900 Subject: [PATCH] Allow image filenames without extension by using imghdr instead of mimetypes --- tweepy/api.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index b627f07..fc9c96e 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -5,7 +5,7 @@ from __future__ import print_function import os -import mimetypes +import imghdr import six @@ -1353,11 +1353,10 @@ class API(object): fp = f # image must be gif, jpeg, or png - file_type = mimetypes.guess_type(filename) + file_type = imghdr.what(filename) if file_type is None: raise TweepError('Could not determine file type') - file_type = file_type[0] - if file_type not in ['image/gif', 'image/jpeg', 'image/png']: + if file_type not in ['gif', 'jpeg', 'png']: raise TweepError('Invalid file type for image: %s' % file_type) if isinstance(filename, six.text_type): -- 2.25.1