I am getting socket error for large file transfer on windows
(100MB+) Working fine for files <50MB. Everything is working fine on mac.. 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') cheers Thomas 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.set_debuglevel(0) 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' import urllib2 import urllib2_file #URL = '' FILE= 'c:/Documents and
Settings/Administrator/Desktop/TM_A5_Bulk.pdf'; f = file(FILE, "rb") data = ""> f.close() post_multipart("192.168.100.233","/UploaderHttp/",[('test','valTest')],[('FILE1','TM_A5_Bulk.pdf',data)]); |
-- http://mail.python.org/mailman/listinfo/python-list