简体   繁体   English

UnicodeDecodeError:'utf8'编解码器无法解码位置11的字节0x80:无效的起始字节

[英]UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 11: invalid start byte

I am trying to write data into an excel sheet using the utf-8 encoding. 我正在尝试使用utf-8编码将数据写入Excel工作表。 Right now i get the following error with complete traceback --> 现在我得到以下错误,具有完整的追溯->

Traceback (most recent call last):
File "C:\Users\varun\Desktop\Python_testfiles\Reports      Automation\Txn.py", line 142, in <module>
domesticsheet.write(row, j, txn[payuid][j])
File "C:\Python27\lib\site-packages\xlwt\Worksheet.py", line 1030, in write
self.row(r).write(c, label, style)
File "C:\Python27\lib\site-packages\xlwt\Row.py", line 240, in write
StrCell(self.__idx, col, style_index, self.__parent_wb.add_str(label))
File "C:\Python27\lib\site-packages\xlwt\Workbook.py", line 326, in add_str
return self.__sst.add_str(s)
File "C:\Python27\lib\site-packages\xlwt\BIFFRecords.py", line 24, in add_str
s = unicode(s, self.encoding)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 11:       invalid start byte

The main issue is that i get this error randomly. 主要问题是我随机得到此错误。 I ran the code for data corresponding to some other day and it ran just fine. 我运行了对应于某天的数据代码,并且运行得很好。 I tried using "utf-16" and "ascii" encoding as well instead of utf - 8 but the error persists(the error statement changed, though.) 我也尝试使用“ utf-16”和“ ascii”编码代替utf-8,但错误仍然存​​在(但错误声明已更改。)

Is there some way i can get rid of this error? 有什么办法可以摆脱这个错误? Also, i would like to know why this error comes(I am a beginner at python). 另外,我想知道为什么会出现此错误(我是python的初学者)。 Any help will be highly appreciated. 任何帮助将不胜感激。 Is it necessary to even provide some encoding type? 是否有必要提供某种编码类型?

If you need to see the code it is as follows--> 如果您需要查看代码,则如下所示->

    filehandler[booknumber] = xlwt.Workbook(encoding = "utf-8")
    domesticsheet = filehandler[booknumber].add_sheet("Domestic_txn" + `booknumber`, cell_overwrite_ok=True)
    for k in range(len(header)):
        domesticsheet.write(0,k,header[k]);
    for j in range(len(txn[payuid])):
        domesticsheet.write(row, j, txn[payuid][j])

Bytes in the range 0x80 - 0xBF are reserved in UTF-8 encoding as continuation bytes. 0x80-0xBF范围内的字节以UTF-8编码形式保留为连续字节。

0x00 - 0x7F - Single byte sequence, backwards compatible with ASCII
0x80 - 0xBF - Continuation byte for multi byte sequences
0xC0 - 0xDF - Starter byte for two byte sequence
0xE0 - 0xEF - Starter byte for three byte sequence
0xF0 - 0xF7 - Starter byte for four byte sequence
0xF8 - 0xFB - Starter byte for five byte sequence (overlong encoding)
0xFC - 0xFD - Starter byte for six byte sequence (overlong encoding)
0xFE - 0xFF - Illegal bytes

What Python is complaining about is that your data doesn't contain a valid starter byte before a continuation byte. Python抱怨的是您的数据在连续字节之前不包含有效的起始字节。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python UnicodeDecodeError:&#39;utf8&#39;编解码器无法解码位置74的字节0x80:无效的起始字节 - Python UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 74: invalid start byte Python:UnicodeDecodeError:'utf-8'编解码器无法解码 position 中的字节 0x80 0:无效起始字节 - Python: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte UnicodeDecodeError:&#39;utf-8&#39;编解码器无法解码位置0的字节0x80:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte UnicodeDecodeError: &#39;utf-8&#39; 编解码器无法解码位置 3131 中的字节 0x80:起始字节无效 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte Python utf8编解码器无法解码位置103的字节0x80:无效的起始字节 - Python utf8 codec can't decode byte 0x80 in position 103:invalid start byte 错误:'utf8'编解码器无法解码位置0中的字节0x80:无效的起始字节 - Error: 'utf8' codec can't decode byte 0x80 in position 0: invalid start byte UnicodeDecodeError:&#39;utf-8&#39;编解码器无法解码位置3131中的字节0x80:我的代码中的无效起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 3131: invalid start byte in my code 在Windows上使用python错误:UnicodeDecodeError:&#39;utf-8&#39;编解码器无法解码位置110的字节0x80:无效的起始字节 - using python on windows error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 110: invalid start byte 'utf-8' 编解码器无法解码 position 中的字节 0x80 28:起始字节无效 - 'utf-8' codec can't decode byte 0x80 in position 28: invalid start byte UnicodeDecodeError:“ utf8”编解码器无法解码位置661中的字节0x92:无效的起始字节 - UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 661: invalid start byte
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM