From 61f16d1ddcf4729945ce7b0b9bfbd94b75dc4b92 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sat, 24 Nov 2012 22:01:16 -0500 Subject: [PATCH] Handle files as well. --- requests/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 84fae6e..4025dae 100644 --- a/requests/models.py +++ b/requests/models.py @@ -542,7 +542,11 @@ class Request(object): content_type = 'application/x-www-form-urlencoded' self.headers['Content-Length'] = '0' - if body is not None: + if isinstance(body, file): + body.seek(0, 2) + self.headers['Content-Length'] = str(body.tell()) + body.seek(0, 0) + elif body is not None: self.headers['Content-Length'] = str(len(body)) # Add content-type if it wasn't explicitly provided. -- 2.34.1