From a19d8f3d0a6ac1051041f4317f7b1b550e386b48 Mon Sep 17 00:00:00 2001 From: keatonconrad Date: Fri, 18 Dec 2020 23:14:59 -0600 Subject: [PATCH] Fixed None value error in f.read() --- tweepy/api.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index b426d79..cf92739 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -221,7 +221,10 @@ class API(object): """ f = kwargs.pop('file', None) - file_type = imghdr.what(filename, h=f.read()) or mimetypes.guess_type(filename)[0] + 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] if file_type == 'gif': max_size = 14649 else: @@ -1418,7 +1421,10 @@ class API(object): # image must be gif, jpeg, png, webp if not file_type: - file_type = imghdr.what(filename, h=f.read()) or mimetypes.guess_type(filename)[0] + 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] if file_type is None: raise TweepError('Could not determine file type') if file_type in ['gif', 'jpeg', 'png', 'webp']: -- 2.25.1