diff --git a/requests/models.py b/requests/models.py index 84fae6e3..4025dae7 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.