From: keatonconrad Date: Sat, 19 Dec 2020 05:14:59 +0000 (-0600) Subject: Fixed None value error in f.read() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a19d8f3d0a6ac1051041f4317f7b1b550e386b48;p=tweepy.git Fixed None value error in f.read() --- 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']: