From 7aed558947f2385cd8d7cb23d74083996bd2ccab Mon Sep 17 00:00:00 2001 From: keatonconrad Date: Tue, 22 Dec 2020 11:51:22 -0600 Subject: [PATCH] Resets cursor to beginning of file after guessing file type --- tweepy/api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tweepy/api.py b/tweepy/api.py index cf92739..2a65731 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -225,6 +225,8 @@ class API(object): 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 + if file_type == 'gif': max_size = 14649 else: @@ -1425,6 +1427,8 @@ class API(object): 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 + if file_type is None: raise TweepError('Could not determine file type') if file_type in ['gif', 'jpeg', 'png', 'webp']: -- 2.25.1