From: Ian Cordasco Date: Thu, 28 Mar 2013 03:26:11 +0000 (-0400) Subject: This should take care of #1266 X-Git-Tag: v1.2.0~2^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1d5c4f3f0f49e04165303952ccc5fd1c70aee7c1;p=services%2Fpython-requests.git 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. --- diff --git a/requests/models.py b/requests/models.py index fe384a1..1451800 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'