Message165093
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. |
|
Date |
User |
Action |
Args |
2012-07-09 16:19:53 | tzs | set | recipients:
+ tzs, tim.golden, Ramchandra Apte |
2012-07-09 16:19:53 | tzs | set | messageid: <1341850793.81.0.176061555511.issue15267@psf.upfronthosting.co.za> |
2012-07-09 16:19:53 | tzs | link | issue15267 messages |
2012-07-09 16:19:52 | tzs | create | |
|