From e53b9ddce159ea0f75dc73e8d2a3781253b973b9 Mon Sep 17 00:00:00 2001 From: Harmon Date: Tue, 12 Jan 2021 14:33:07 -0600 Subject: [PATCH] Fix logic in determining number of segments in API.chunked_upload --- tweepy/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tweepy/api.py b/tweepy/api.py index a675b94..4ed42d1 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -296,7 +296,8 @@ class API: chunk_size = kwargs.pop('chunk_size', DEFAULT_CHUNKSIZE) chunk_size = max(min(chunk_size, MAX_CHUNKSIZE), MIN_CHUNKSIZE) - segments = file_size // (chunk_size * 1024) + bool(file_size % chunk_size) + segments, remainder = divmod(file_size, chunk_size * 1024) + segments += bool(remainder) for segment_index in range(segments): # The APPEND command returns an empty response body -- 2.25.1