From 9d18f08c3c6b550462f1972ebc70edc53036ea7c Mon Sep 17 00:00:00 2001 From: Keaton Conrad Date: Tue, 22 Dec 2020 12:33:51 -0600 Subject: [PATCH] Resolving media_upload conflicts Co-authored-by: Harmon --- tweepy/api.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 2a65731..2bf4751 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -1423,12 +1423,11 @@ class API(object): # image must be gif, jpeg, png, webp if not file_type: - if f is None: - file_type = imghdr.what(filename) or mimetypes.guess_type(filename)[0] - else: - file_type = imghdr.what(filename, h=f.read()) or mimetypes.guess_type(filename)[0] - f.seek(0) # Reset to beginning of file - + h = None + if f is not None: + h = f.read(32) + f.seek(0) + file_type = imghdr.what(filename, h=h) or mimetypes.guess_type(filename)[0] if file_type is None: raise TweepError('Could not determine file type') if file_type in ['gif', 'jpeg', 'png', 'webp']: -- 2.25.1