From 033dfc165d0c0946e95f5b3ac290c6c8fe3a813a Mon Sep 17 00:00:00 2001 From: Casey Davidson Date: Wed, 8 Jun 2016 21:47:34 -0700 Subject: [PATCH] Raise an error if body is not null, has not length and is not streamable. --- requests/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requests/models.py b/requests/models.py index 365c0ed8..eb68289b 100644 --- a/requests/models.py +++ b/requests/models.py @@ -526,6 +526,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): self.headers['Content-Length'] = builtin_str(length) elif is_stream and not length: self.headers['Transfer-Encoding'] = 'chunked' + else: + assert False, "If body is not null, it must either have a length or be streamable" elif (self.method not in ('GET', 'HEAD')) and (self.headers.get('Content-Length') is None): self.headers['Content-Length'] = '0'