Unicode Decode Error
Pratik Khemka
pratikkhemka at hotmail.com
Mon Oct 11 17:44:25 EDT 2010
This is the original full traceback. when I was getting the Unicode Decode Error..
Traceback (most recent call last):
File "C:\Documents and Settings\pkhemka\My Documents\merge_py.py", line 315, i
n <module>
wbk.save('p4_merge.xls')
File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 634, in save
doc.save(filename, self.get_biff_data())
File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 609, in get_biff_d
ata
shared_str_table = self.__sst_rec()
File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 571, in __sst_rec
return self.__sst.get_biff_record()
File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 53, in get_biff
_record
self._add_to_sst(s)
File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 66, in _add_to_
sst
u_str = upack2(s, self.encoding)
File "C:\Python25\Lib\site-packages\xlwt\UnicodeUtils.py", line 50, in upack2
us = unicode(s, encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 152: ordina
l not in range(128)
I tried to solve it using this wbk = xlwt.Workbook('utf-8')... The problem still persists. Is there a way I can solve this problem..?
Traceback (most recent call last):
File "C:\Documents and Settings\pkhemka\My Documents\merge_py.py", line 229, i
n <module>
sheet.write(x,4,Technical_detail,datastyle)
File "C:\Python25\Lib\site-packages\xlwt\Worksheet.py", line 1003, in write
self.row(r).write(c, label, style)
File "C:\Python25\Lib\site-packages\xlwt\Row.py", line 231, in write
StrCell(self.__idx, col, style_index, self.__parent_wb.add_str(label))
File "C:\Python25\lib\site-packages\xlwt\Workbook.py", line 306, in add_str
return self.__sst.add_str(s)
File "C:\Python25\Lib\site-packages\xlwt\BIFFRecords.py", line 24, in add_str
s = unicode(s, self.encoding)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 152: unexpec
ted code byte
From: ian.g.kelly at gmail.com
Date: Fri, 8 Oct 2010 16:59:19 -0600
Subject: Re: Unicode Decode Error
To: python-list at python.org
On Fri, Oct 8, 2010 at 3:31 PM, Pratik Khemka <pratikkhemka at hotmail.com> wrote:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x92 in position 152: ordinal not in range(128). Can someone please help me with this error
The error occurs in line wbk.save(p4_merge.xls). I have used import xlwt..Can someone just tell what do I need to do to get rid of this error. I read other forums which explain the error but do not solve it. Thanks in advance..
You're writing non-ascii data to the workbook, which is then trying to decode it using the default ascii encoding, which will fail. When you create the workbook, you need to specify the correct encoding, e.g.:
wbk = xlwt.Workbook('utf-8')
or whatever encoding you're actually using.
Cheers,
Ian
-- http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101012/91374ac9/attachment.html>
More information about the Python-list
mailing list