Handle files as well.
authorIan Cordasco <graffatcolmingov@gmail.com>
Sun, 25 Nov 2012 03:01:16 +0000 (22:01 -0500)
committerIan Cordasco <graffatcolmingov@gmail.com>
Sun, 25 Nov 2012 03:02:14 +0000 (22:02 -0500)
requests/models.py

index 84fae6e36843241a283e08e5c163ad16005e605e..4025dae73dc0389137f6b0917ce1f23aface6960 100644 (file)
@@ -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.