[英]UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 377826: invalid start byte
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")
. if uID in repo.git.log():
的 uID 恰好在该行执行以下代码片段时出现以下错误,问题出在repo.git.log()
中,我已经查看了 Stack 上的所有类似问题建议使用decode("utf-8")
溢出。
how do I convert repo.git.log()
into decode("utf-8")
?如何将
repo.git.log()
转换为decode("utf-8")
?
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 377826: invalid start byte
Relavant code:相关代码:
..................
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 is a smart quote(') of Windows-1252. 0x92是Windows-1252的智能引号(')。 It simply doesn't exist in unicode, therefore it can't be decoded.
它根本不存在于unicode中,因此无法解码。
Maybe your file was edited by a Windows machine which basically caused this problem? 也许您的文件是由Windows计算机编辑的,这基本上导致了此问题?
使用encoding='cp1252'
将解决此问题。
After good research, I got the solution.经过很好的研究,我得到了解决方案。 In my case,
datadump.json<\/code><\/strong> file was having the issue.
就我而言,
datadump.json<\/code><\/strong>文件有问题。
Simply Open the file in notepad format只需以记事本格式打开文件<\/li>
Click on save as option点击另存为选项<\/li>
![](/img/trans.png)
Go to encoding section below & Click on "UTF-8"转到下面的编码部分并单击“UTF-8”<\/li>
Save the file.保存文件。<\/li><\/ul> Now you can try running the command.
现在您可以尝试运行该命令。 You are good to go :)
你已准备好出发 :)
For your reference, I have attached images below.供您参考,我在下面附上了图片。
"
0x92 does not exist in the encoding UTF-8.编码 UTF-8 中不存在 0x92。 As Exceen stated in his answer 0x92 is used in Windows-1252 as a smart quote.
正如 Exceen 在他的回答中所说,0x92 在 Windows-1252 中用作智能引用。 The way to resolve this is to use the windows 1252 encoding or to update the smart quote to a normal quote.
解决此问题的方法是使用 windows 1252 编码或将智能报价更新为正常报价。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.