From 1d5c4f3f0f49e04165303952ccc5fd1c70aee7c1 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 27 Mar 2013 23:26:11 -0400 Subject: [PATCH] This should take care of #1266 We were sending 'None' as the Content-Length on requests where the body was a generator. This commit should prevent that entirely. --- requests/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/requests/models.py b/requests/models.py index fe384a1b..14518006 100644 --- a/requests/models.py +++ b/requests/models.py @@ -349,7 +349,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): ]) try: - length = str(super_len(data)) + length = super_len(data) except (TypeError, AttributeError): length = False @@ -360,7 +360,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): raise NotImplementedError('Streamed bodies and files are mutually exclusive.') if length: - self.headers['Content-Length'] = length + self.headers['Content-Length'] = str(length) else: self.headers['Transfer-Encoding'] = 'chunked' # Check if file, fo, generator, iterator. @@ -392,7 +392,9 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): self.headers['Content-Length'] = str(body.tell()) body.seek(0, 0) elif body is not None: - self.headers['Content-Length'] = str(len(body)) + l = super_len(body) + if l: + self.headers['Content-Length'] = super_len(l) elif self.method not in ('GET', 'HEAD'): self.headers['Content-Length'] = '0'