diff -r 4e85e4743757 Lib/httplib.py --- a/Lib/httplib.py Fri Jul 27 14:05:46 2012 +0100 +++ b/Lib/httplib.py Mon Jul 30 17:26:59 2012 +0900 @@ -966,7 +966,7 @@ thelen = None try: thelen = str(len(body)) - except TypeError, te: + except (TypeError, AttributeError): # If this is a file-like object, try to # fstat its file descriptor try: diff -r 4e85e4743757 Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Fri Jul 27 14:05:46 2012 +0100 +++ b/Lib/test/test_httplib.py Mon Jul 30 17:26:59 2012 +0900 @@ -4,6 +4,7 @@ import StringIO import socket import errno +import tempfile import unittest TestCase = unittest.TestCase @@ -240,6 +241,20 @@ conn.request('GET', '/foo', body) self.assertTrue(sock.data.startswith(expected)) + def test_send_tempfile(self): + expected = 'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \ + 'Accept-Encoding: identity\r\nContent-Length:' + + body = tempfile.TemporaryFile() + body.write("fake data") + body.seek(0) + + conn = httplib.HTTPConnection('example.com') + sock = FakeSocket(body) + conn.sock = sock + conn.request('GET', '/foo', body) + self.assertTrue(sock.data.startswith(expected)) + def test_send(self): expected = 'this is a test this is only a test' conn = httplib.HTTPConnection('example.com')