UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 178175077: invalid start byte

UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 178175077: invalid start byte

我正在尝试将 gerrit uid 编码为 utf-8 并将 运行 编码为以下错误,它大部分时间都有效,但对于某些 uid 随机 运行 为以下错误,我看过类似的Whosebug 上的帖子建议使用 ISO-8859-1,但 utf-8 对我来说大部分时间都有效,如何修复它?

uid = Ia7324f6443b3db5d55113a221dc0791bb5a38799
uID = gerritInfo['id'].encode("utf-8")

错误堆栈:-

 result=main()
  File "/prj/team/location/script", line 1363, in main
    (picked_gerrit,uID,email_state) = cherrypick_gerrit(buildDir,manifest,gerrit,patch,False,errorLog,picklogfd)
  File "/prj/team/location/script", line 356, in cherrypick_gerrit
    if uID in repo.git.log():
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 450, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 902, in _call_process
    return self.execute(make_call(), **_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 698, 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 0xf6 in position 178175077: invalid start byte

# coding=utf-8 添加到 python 文件的第一行。

基于https://github.com/gitpython-developers/GitPython/issues/237,你可以试试下面的方法,使用stdout_as_string=False

if uID in repo.git.log(stdout_as_string=False)