From 71a05cf28985da6bb56ee27b91d7cd005ce8da9d Mon Sep 17 00:00:00 2001 From: David Black Date: Tue, 16 Jun 2020 20:53:07 +1000 Subject: [PATCH] Avoid an unnecessary computation of the length of data for non-stream requests (which determines content-length based upon body content). --- requests/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requests/models.py b/requests/models.py index 6e20ac4d..ae6eb708 100644 --- a/requests/models.py +++ b/requests/models.py @@ -473,12 +473,12 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): not isinstance(data, (basestring, list, tuple, Mapping)) ]) - try: - length = super_len(data) - except (TypeError, AttributeError, UnsupportedOperation): - length = None - if is_stream: + try: + length = super_len(data) + except (TypeError, AttributeError, UnsupportedOperation): + length = None + body = data if getattr(body, 'tell', None) is not None: