From 4937da41d26e3b501e3810f6ac4e4e4c9df722dd Mon Sep 17 00:00:00 2001 From: Harmon Date: Tue, 12 Jan 2021 08:52:59 -0600 Subject: [PATCH] Fix file parameter size determination in API.media_upload --- tweepy/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tweepy/api.py b/tweepy/api.py index 1f46c20..ae6655f 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -237,8 +237,10 @@ class API: location = f.tell() h = f.read(32) f.seek(location) + size_bytes = os.stat(f.fileno()).st_size + else: + size_bytes = os.path.getsize(filename) file_type = imghdr.what(filename, h=h) or mimetypes.guess_type(filename)[0] - size_bytes = os.path.getsize(filename) if file_type not in IMAGE_TYPES and file_type not in CHUNKED_TYPES: raise TweepError(f'unsupported media type: {file_type}') -- 2.25.1