python - UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) -
i have written code below provides path excel file created xlwt module
master_path = r"c:\users\nbt8ye8\documents\docs\report automation\kbe reporting\reports" master_excel_file_raw = "kbe master data.xls" master_excel_file = os.path.join(master_path, master_excel_file_raw) then later in code create excel file (which works without problem) code below:
master_excel_wbook = xlwt.workbook() master_excel_wsheet = master_excel_wbook.add_sheet("all data", cell_overwrite_ok=true) master_excel_wbook.save(master_excel_file) master_excel_wbook.save(tempfile.temporaryfile()) however when run code gives me errors below.
traceback (most recent call last): file "c:\users\nbt8ye8\workspace\report automation\import_data.py", line 1225, in <module> createexcelfile() file "c:\users\nbt8ye8\workspace\report automation\import_data.py", line 1219, in createexcelfile master_excel_wbook.save(master_excel_file) file "build\bdist.win32\egg\xlwt\workbook.py", line 662, in save file "build\bdist.win32\egg\xlwt\workbook.py", line 637, in get_biff_data file "build\bdist.win32\egg\xlwt\workbook.py", line 599, in __sst_rec file "build\bdist.win32\egg\xlwt\biffrecords.py", line 76, in get_biff_record file "build\bdist.win32\egg\xlwt\biffrecords.py", line 91, in _add_to_sst file "build\bdist.win32\egg\xlwt\unicodeutils.py", line 50, in upack2 unicodedecodeerror: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128) does know how resolve issue? have tried encoding , decoding strings , far has not worked highly did not correctly. apprecieated. thank you!
@ryang correct, error thrown because there unicode data in excel file. once modified excel file remove unicode data problem resolved. again.
Comments
Post a Comment