From 8873a090979ffb627b21d54c04e7ddd1943eea03 Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Fri, 17 Jun 2016 13:27:02 -0500 Subject: [PATCH] Fall back to streaming --- requests/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/requests/utils.py b/requests/utils.py index f1e40bde..c847e601 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -83,7 +83,8 @@ def super_len(o): # is actually a special file descriptor like stdin. In this # instance, we don't know what the length is, so set it to zero and # let requests chunk it instead. - current_position = total_length + if total_length is not None: + current_position = total_length if hasattr(o, 'seek') and total_length is None: # StringIO has a notimplemented fileno @@ -98,6 +99,9 @@ def super_len(o): # seek back to current position to support partially read file-like o.seek(current_position or 0) + if total_length is None: + total_length = 0 + return max(0, total_length - current_position)