Hi all
import httplib, mimetypes
import os; def
get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream' filepath= 'c:/Documents and
Settings/Administrator/Desktop/tmp/test.pdf';
f = open(filepath, "rb") data = "">f.close() (filedir, filename) =
os.path.split(filepath)
filename=unicode(filename); #file = ('file', filename, data) #This won't work will give a UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 10: ordinal not in range(128) file = ('file', filename, 'data'*100) #this will work fine #file = ('file', 'test.pdf', data) #This also works fine files = [file] CRLF = '\r\n' L = [] for (key, filename, value) in files: L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append(value) body = CRLF.join(L) print "ok"
can anyone put some light.. whats going
behind..
cheers
Thomas
|
-- http://mail.python.org/mailman/listinfo/python-list