错误UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0xff:无效的起始字节

派:

https://github.com/affinelayer/pix2pix-tensorflow/tree/master/tools

在上述站点上编译“ process.py”时发生错误。

 python tools/process.py --input_dir data --            operation resize --outp
ut_dir data2/resize
data/0.jpg -> data2/resize/0.png

追溯(最近一次通话):

File "tools/process.py", line 235, in <module>
  main()
File "tools/process.py", line 167, in main
  src = load(src_path)
File "tools/process.py", line 113, in load
  contents = open(path).read()
      File"/home/user/anaconda3/envs/tensorflow_2/lib/python3.5/codecs.py", line 321, in decode
  (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode     byte 0xff in position 0: invalid start byte

错误原因是什么?Python的版本是3.5.2。

阿尔夫:

Python尝试将字节数组(bytes假定为utf-8编码的字符串)转换为unicode字符串(str)。当然,此过程是根据utf-8规则进行的解码。尝试此操作时,会遇到utf-8编码的字符串中不允许的字节序列(即位置0处的此0xff)。

由于您没有提供我们可以查看的任何代码,因此我们只能猜测其余的代码。

从堆栈跟踪中,我们可以假定触发操作是从文件(contents = open(path).read())中读取数据我建议以如下方式重新编码:

with open(path, 'rb') as f:
  contents = f.read()

b在该模式说明open(),指出该文件应作为二进制来处理,所以contents仍将是一个bytes这样就不会发生解码尝试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误 UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0 中的字节 0xff:套接字编程中的无效起始字节

json.dump-UnicodeDecodeError:'utf8'编解码器无法解码位置0的字节0xbf:无效的起始字节

UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0x9d:执行b.decode()时无效的起始字节

UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0 中的字节 0x80:起始字节无效

UnicodeDecodeError:“ utf8”编解码器无法解码位置0的字节0xa5:无效的起始字节

Gensim W2V - UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0 中的字节 0x80:起始字节无效

UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0x90:无效的起始字节

烧瓶UnicodeDecodeError:'utf-8'编解码器无法解码位置0的字节0xb3:无效的起始字节

Google SDK gcloud 崩溃(UnicodeDecodeError):“utf8”编解码器无法解码位置 29 中的字节 0xf8:起始字节无效

UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 3 中的字节 0x95:无效的起始字节 (Python) 套接字编程

UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 2 中的字节 0xbe:起始字节无效

UnicodeDecodeError:'utf-8'编解码器无法解码位置35的字节0x96:无效的起始字节

UnicodeDecodeError:'utf-8'编解码器无法解码位置14的字节0xb9:无效的起始字节

“UnicodeDecodeError:‘utf-8’编解码器无法解码位置 2491 中的字节 0xad:起始字节无效”

UnicodeDecodeError:'utf-8'编解码器无法解码位置98的字节0xb1:无效的起始字节

如何解决UnicodeDecodeError:'utf-8'编解码器无法解码位置3的字节0xa1:无效的起始字节?

UnicodeDecodeError:“ utf-8”编解码器无法解码位置10的字节0xa9:无效的起始字节

Python3:UnicodeDecodeError:'utf-8'编解码器无法解码位置 1 的字节 0x83:无效的起始字节

“utf8”编解码器无法解码位置 0 中的字节 0xb5:无效起始字节错误

错误:“utf-8”编解码器无法解码位置 14 中的字节 0xb0:起始字节无效

PyArmor 错误“utf-8”编解码器无法解码位置 594 中的字节 0x83:起始字节无效

使用pyinstaller时出错:UnicodeDecodeError:'utf-8'编解码器无法解码字节0xff

Robot_framework UnicodeDecodeError:'utf-8'编解码器无法解码位置42的字节0xe0:无效的连续字节

pip install和UnicodeDecodeError:'utf-8'编解码器无法解码位置9的字节0xe0:无效的连续字节

UnicodeDecodeError:“ utf-8”编解码器无法解码位置6的字节0xe1:无效的连续字节

UnicodeDecodeError:'utf-8'编解码器无法解码位置1的字节0xe3:无效的继续字节

App Engine-Python:UnicodeDecodeError:“ utf8”编解码器无法解码位置1的字节0xe1:无效的连续字节

UnicodeDecodeError:“ utf8”编解码器无法解码位置1的字节0xa9

发生异常:UnicodeDecodeError'utf-8'编解码器无法解码位置的字节0xf1