UnicodeDecodeError

Thomas Thomas thomas at eforms.co.nz
Thu May 5 08:15:17 EDT 2005


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.read()
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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050506/f35b940f/attachment.html>


More information about the Python-list mailing list