问题描述
如果uID在repo.git.log()中:,
,则执行以下代码片段时,出现以下错误:是在
repo.git.log()
中,我已经看过堆栈溢出中的所有类似问题,它建议使用 decode(utf-8 )
。
I am getting the following error while executing the below code snippet exactly at the line if uID in repo.git.log():
,the problem is in repo.git.log()
, I have looked at all the similar questions on Stack Overflow which suggests to use decode("utf-8")
.
如何将 repo.git.log()
转换为 decode(utf-8)
?
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 377826: invalid start byte
相关代码:
..................
uID = gerritInfo['id'].decode("utf-8")
if uID in repo.git.log():
inwslist.append(gerritpatch)
.....................
Traceback (most recent call last):
File "/prj/host_script/script.py", line 1417, in <module>
result=main()
File "/prj/host_script/script.py", line 1028, in main
if uID in repo.git.log():
File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 431, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 802, in _call_process
return self.execute(make_call(), **_kwargs)
File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 610, in execute
stdout_value = stdout_value.decode(defenc)
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 377826: invalid start byte
推荐答案
0x92是Windows-1252的智能报价(')。它根本不存在于unicode中,因此无法解码。
0x92 is a smart quote(’) of Windows-1252. It simply doesn't exist in unicode, therefore it can't be decoded.
也许你的文件是由Windows机器编辑的,这基本上导致了这个问题?
Maybe your file was edited by a Windows machine which basically caused this problem?
这篇关于UnicodeDecodeError:'utf8'编解码器无法解码位于377826的字节0x92:无效的起始字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!