Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnicodeDecodeError with xlwt

I'm using python with xlwt and have a problem

My code:

tickets = cursor.fetchall ()
largo = len(tickets)
cursor.close ()
conn.close ()

row = 4
for t in tickets:

  hoja.write(row, 1, t[0])
  hoja.write(row, 2, epoch2fecha(t[1]))
  hoja.write(row, 3, epoch2fecha(t[12]))
  hoja.write(row, 6, t[10])
  hoja.write(row, 7, t[9])
  hoja.write(row, 8, t[6])
  hoja.write(row, 9, t[3])
  row += 1
  if(row == largo+1):
     break
libro.save('Informe.xls')

Error:

libro.save('informe.xlsx')
File "build/bdist.linux-x86_64/egg/xlwt/Workbook.py", line 662, in save
File "build/bdist.linux-x86_64/egg/xlwt/Workbook.py", line 637, in get_biff_data
File "build/bdist.linux-x86_64/egg/xlwt/Workbook.py", line 599, in __sst_rec
File "build/bdist.linux-x86_64/egg/xlwt/BIFFRecords.py", line 76, in get_biff_record
File "build/bdist.linux-x86_64/egg/xlwt/BIFFRecords.py", line 91, in _add_to_sst
File "build/bdist.linux-x86_64/egg/xlwt/UnicodeUtils.py", line 50, in upack2
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 6: ordinal not in range(128)
like image 231
R. Stark Avatar asked Jan 12 '23 18:01

R. Stark


1 Answers

Have you tried encoding latin-1 for workbook??

from xlwt import Workbook

hoja = Workbook(encoding='latin-1')
like image 176
hsvyas4u Avatar answered Jan 22 '23 05:01

hsvyas4u