uploading large file 100mb
Thomas
thomas at eforms.co.nz
Fri Apr 29 00:00:59 EDT 2005
Hi I am getting the following error when uploading large files.
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ## working on region in file
c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-1156QtG.py...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-1156QtG.py", line 79, in ?
post_multipart("192.168.100.233","/UploaderHttp/",[('test','valTest')],[('FI
LE1','TM_A5_Bulk.pdf',data)]);
File "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-1156QtG.py", line 17, in
post_multipart
h.send(body)
File "C:\Python23\lib\httplib.py", line 576, in send
self.sock.sendall(str)
File "<string>", line 1, in sendall
socket.error: (10055, 'No buffer space available')
>>>
Thanks
Thomas
The code that I am using
----------------------------------------------------------------------
import httplib, mimetypes
def post_multipart(host, selector, fields, files):
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be
uploaded as files
Return the server's response page.
"""
content_type, body = encode_multipart_formdata(fields, files)
h = httplib.HTTP(host)
h.putrequest('POST', selector)
h.putheader('content-type', content_type)
h.putheader('content-length', str(len(body)))
h.endheaders()
#print body;
h.send(body)
errcode, errmsg, headers = h.getreply()
return h.file.read()
def encode_multipart_formdata(fields, files):
"""
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be
uploaded as files
Return (content_type, body) ready for httplib.HTTP instance
"""
BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$'
CRLF = '\r\n'
L = []
for (key, value) in fields:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
for (key, filename, value) in files:
L.append('--' + BOUNDARY)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"'
% (key, filename))
L.append('Content-Type: %s' % get_content_type(filename))
L.append('')
L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')
body = CRLF.join(L)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
FILE= 'c:/Documents and Settings/Administrator/Desktop/TM_A5_Bulk.pdf';
f = file(FILE, "rb")
data = f.read()
f.close()
post_multipart("192.168.100.233","/UploaderHttp/",[('test','valTest')],[('FI
LE1','TM_A5_Bulk.pdf',data)]);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050429/789365ff/attachment.html>
More information about the Python-list
mailing list