简体   繁体   English

UnicodeDecodeError:“utf8”编解码器无法解码 position 中的字节 0x92 377826:无效的起始字节

[英]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>
  • 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.供您参考,我在下面附上了图片。

    Step1<\/a>步骤1<\/a>

    Step2<\/a>第2步<\/a>

    Step3<\/a>第三步<\/a>

    "

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.

相关问题 UnicodeDecodeError:“utf-8”编解码器无法解码 position 35 中的字节 0x96:无效的起始字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 35: invalid start byte docker ddev .UnicodeDecodeError: &#39;utf-8&#39; 编解码器无法解码位置 235 中的字节 0xe9:继续字节无效 - docker ddev .UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 235: invalid continuation byte "UnicodeDecodeError:“charmap”编解码器无法解码位置 X 中的字节 0x9d:字符映射到<undefined>" - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position X: character maps to <undefined> UnicodeDecodeError:“charmap”编解码器无法解码 position 2310 中的字节 0x81:字符映射到<undefined></undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 2310: character maps to <undefined> UnicodeDecodeError: &#39;charmap&#39; 编解码器无法解码位置 73776 中的字节 0x81 - UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 73776 升级pip时出错:UnicodeDecodeError:'utf-8'编解码器无法解码字节 - Error while upgrading pip: UnicodeDecodeError: 'utf-8' codec can't decode byte 如何修复 UnicodeDecodeError:“ascii”编解码器无法在 Windows 上解码字节 - how to fix UnicodeDecodeError: 'ascii' codec can't decode byte on windows UnicodeDecodeError:“charmap”编解码器无法解码 position 8024 中的字节 0x9d:字符映射到<undefined>将 output 重定向到磁盘时</undefined> - UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 8024: character maps to <undefined> when re-directing output to disk Windows上的closurebuilder.py错误:“无法解码字节0x8f” - closurebuilder.py error on Windows: “can't decode byte 0x8f” SyntaxError: (unicode error) 'unicodeescape' 编解码器无法解码 position 中的字节 - SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM