Index: Lib/http/client.py =================================================================== --- Lib/http/client.py (revision 85169) +++ Lib/http/client.py (working copy) @@ -917,6 +917,8 @@ for i, one_value in enumerate(values): if hasattr(one_value, 'encode'): values[i] = one_value.encode('ascii') + elif isinstance(one_value, int): + values[i] = str(one_value).encode('ascii') value = b'\r\n\t'.join(values) header = header + b': ' + value self._output(header) Index: Lib/test/test_httplib.py =================================================================== --- Lib/test/test_httplib.py (revision 85169) +++ Lib/test/test_httplib.py (working copy) @@ -90,6 +90,15 @@ conn.request('POST', '/', body, headers) self.assertEqual(conn._buffer.count[header.lower()], 1) + def test_putheader(self): + conn = client.HTTPConnection('example.com') + conn.sock = FakeSocket(None) + conn.putrequest('GET','/') + conn.putheader('Content-length', 42) + print(conn._buffer) + self.assertTrue(b'Content-length: 42' in conn._buffer) + + class BasicTest(TestCase): def test_status_lines(self): # Test HTTP status lines