This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tzs
Recipients Ramchandra Apte, tim.golden, tzs
Date 2012-07-09.16:19:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Here is a program that demonstrates the problem:

    import httplib
    import tempfile

    f = tempfile.TemporaryFile()
    f.write("Hello, Temporary File!")

    c = httplib.HTTPConnection('')
    c.request('POST', '/', f, {'Content-type' : 'application/octet-stream'})

    r = c.getresponse()
    print r.status, r.reason

The expected output is "200 OK", and that's what happens on Mac and almost certainly on Linux. On Windows, this is the result:

    Traceback (most recent call last):
      File "", line 9, in <module>
        c.request('POST', '/', f, {'Content-type' : 'application/octet
      File "C:\Python27\lib\", line 958, in request
        self._send_request(method, url, body, headers)
      File "C:\Python27\lib\", line 989, in _send_request
      File "C:\Python27\lib\", line 964, in _set_content_len
        thelen = str(len(body))
      File "C:\Python27\lib\", line 383, in __getattr__
        a = getattr(file, name)
    AttributeError: 'file' object has no attribute '__len__'

Changing the lines:

    f = tempfile.TemporaryFile()
    f.write("Hello, Temporary File!")


    f = open("temp.file", "w+")
    f.write("Hello, Less Temporary File!")

makes it work on Windows.
Date User Action Args
2012-07-09 16:19:53tzssetrecipients: + tzs, tim.golden, Ramchandra Apte
2012-07-09 16:19:53tzssetmessageid: <>
2012-07-09 16:19:53tzslinkissue15267 messages
2012-07-09 16:19:52tzscreate