I use Python to retrieve data from an MSSQL database using an ODBC connection. Then I try to put the extracted data into an Excel file using xlwt.
However, this generates the following error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd8 in position 20: ordinal not in range(128)
I ran a script to simply print the data and found that the abusive character in the database is O with a slash through it. On a python printout, this displays as "\ xd8".
The worksheet encoding for xlwt is set to UTF-8.
Is there any way to get this directly in Excel?
Edit
Full error message below:
C:\>python dbtest1.py Traceback (most recent call last): File "dbtest1.py", line 24, in <module> ws.write(i,j,item) File "build\bdist.win32\egg\xlwt\Worksheet.py", line 1032, in write File "build\bdist.win32\egg\xlwt\Row.py", line 240, in write File "build\bdist.win32\egg\xlwt\Workbook.py", line 309, in add_str File "build\bdist.win32\egg\xlwt\BIFFRecords.py", line 25, in add_str File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xd8 in position 20: invalid continuation byte
source share