python socket error
Thomas Thomas
thomas at eforms.co.nz
Wed Jun 1 18:31:28 EDT 2005
Is there any getaround for the following error ..
This happens when uploading large files say>50MB..
Python version
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-116V_Z.py", line 87, in ?
httpResult=httpUploadAsset('XXXXXX',filename,fileData)
File "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-116V_Z.py", line 12, in httpUploadAsset
results=post_multipart(theURL,"/UploaderHttp/",fields,files);
File "c:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/python-116V_Z.py", line 30, in post_multipart
h.send(body)
File "C:\Python23\lib\httplib.py", line 579, in send
self.sock.sendall(str)
File "<string>", line 1, in sendall
socket.error: (10055, 'No buffer space available')
Any help
Thomas
----------below the code sample that i am using
import os
import httplib, mimetypes
import os;
def httpUploadAsset(serial,filename,data):
_sessionID='xxxxxxx';
_baseURL='http://xxxxxx.com'
fields = [('serial',serial),('sessionID',_sessionID)]
file = ('file', filename, data)
files = [file]
protocol,theURL=_baseURL.split('http://');
results=post_multipart(theURL,"/UploaderHttp/",fields,files);
print results;
return results;
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()
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'
def getFileData(filename):
try:
f = file(filename, "rb")
data = f.read()
f.close()
except IOError:
return['ERR']
return ['OK',data]
filepath="c:/Documents and Settings/Administrator/Desktop/tmp/TM_A5_Bulk.pdf" #file with size >50MB
fileResult=getFileData(filepath)
filename='TM_A5_Bulk.pdf'
fileData=None
if (fileResult[0]=='OK'):
fileData=fileResult[1];
httpResult=httpUploadAsset('XXXXXX',filename,fileData)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050602/d0f023ca/attachment.html>
More information about the Python-list
mailing list