Hi all, 

I'm trying to create an application that lets users upload an .xls file 
that I then take and feed that uploaded.xls file into my program which 
reads and parses it. However, I am having issues with the utf-8 encoding 
for the Excel files. I have searched everywhere on stackoverflow and 
google, but none of them are working.

Here is my code:

def POST(self):
        x = web.input(calendar_file={}, ref_id='')
        if x:
        ref_id = (x.ref_id if x.ref_id else "")
        filepath=x.calendar_file.filename # replaces the windows-style 
slashes with linux ones.
        fn=filepath.split('/')[-1] # splits the and chooses the last part 
(the filename
        filename = "%s/Users/jl98567/Documents/xMatters_calendar_app/test/" 
+ fn
        fullpath = os.path.join('c:', filename % (ref_id))
        content = x["calendar_file"].file.read()
        with open(fullpath, 'w') as f_out:
        if not f_out:
        raise Exception("Unable to open %s for writing. " % (fullpath))
        f_out.write(content)
        print str(x['calendar_file'].value.encode('utf8','ignore'))
        raise web.seeother('/upload?ref_id=%s&filename=%s' % (ref_id, 
filename))


Here is the error;

<type 'exceptions.UnicodeDecodeError'> at /'ascii' codec can't decode byte 
0xd0 in position 0: ordinal not in 
range(128)PythonC:\Users\jl98567\Documents\xMatters_calendar_app\schedule_web.py
 
in POST, line 45WebPOST http://localhost:8080/
line 45 is: print str(x['calendar_file'].value.encode('utf8','ignore'))

I have tried decoding it and then encoding it similar to this one:

print str(x['calendar_file'].value.decode('utf-8').encode('utf8','ignore'))

 but still doesn't work.

Any suggestions?

Thanks much! 

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to