Tim Smith <t...@tzs.net> added the comment:

Here is a program that demonstrates the problem:

    import httplib
    import tempfile

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

    c = httplib.HTTPConnection('bugs.python.org')
    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 "bad.py", line 9, in <module>
        c.request('POST', '/', f, {'Content-type' : 'application/octet
      File "C:\Python27\lib\httplib.py", line 958, in request
        self._send_request(method, url, body, headers)
      File "C:\Python27\lib\httplib.py", line 989, in _send_request
        self._set_content_length(body)
      File "C:\Python27\lib\httplib.py", line 964, in _set_content_len
        thelen = str(len(body))
      File "C:\Python27\lib\tempfile.py", 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.seek(0)

to:

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

makes it work on Windows.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15267>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to