Hi David, So when I try to print it locally via the terminal, I just get a bunch of webdings style text like this:
■ ♠☺☻ ☺ ☻╒═╒£.←►ô +,∙«0 ░ ☺ H ↨ P ♂ X ♀ ï ☻ Σ♦ ♥ ♫ ♂ ♂ ♂ ♂ ▲► ☺ Sheet1 ▲ ♂ Worksheets ♥ ☺ ... basically unreadable. The method works for .txt files flawlessly, so I know it has to do with the .xls formatting. I tired converting the .xls files to .csv too, but same thing - it's unreadable. Thanks for your input David! On Tue, Feb 4, 2014 at 9:08 PM, David Kopec <[email protected]> wrote: > Hi Jessica, > > I'm not sure this has to do with web.py. Are you able to print the file > when opening it locally in python using the same code? > > On Monday, February 3, 2014 8:52:21 PM UTC-5, Jessica Le wrote: >> >> So after doing more research/testing, it seems like the built in function >> for file upload only seems to work flawlessly for txt files. Is there a >> library out there for other kinds of files? >> >> On Friday, January 17, 2014 3:58:15 PM UTC-6, Jessica Le wrote: >>> >>> 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)Python >>> C:\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 a topic in the > Google Groups "web.py" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/webpy/_i64Ym_Ubxg/unsubscribe. > To unsubscribe from this group and all its topics, 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. > -- 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.
