簡體   English   中英

UnicodeDecodeError:'utf8'編解碼器無法解碼位置178175077中的字節0xf6:無效的起始字節

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

我正在嘗試將gerrit uid編碼為utf-8並遇到以下錯誤,它大多數時候都可以工作,但是對於某些uid卻隨機地遇到了下面的錯誤,我在stackoverflow上查看過類似的帖子,建議嘗試ry 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

基於https://github.com/gitpython-developers/GitPython/issues/237 ,您可以嘗試以下操作,使用stdout_as_string = False

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM