错误信息:

UnicodeDecodeError: ‘gbk' codec can't decode bytes in position : illegal multibyte sequence

这是因为遇到了非法字符,因此在转码的过程中出现了异常。具体哪些字符是非法字符我也搞不清。

[解决办法]

inStr2 = inStr.decode('utf-8', 'ignore')

[补充]

默认的参数就是strict,代表遇到非法字符时抛出异常;
如果设置为ignore,则会忽略非法字符;
如果设置为replace,则会用?号取代非法字符;
如果设置为xmlcharrefreplace,则使用XML的字符引用。

相关文章:

  • 2021-07-22
  • 2021-09-21
  • 2022-01-16
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2021-04-19
  • 2021-12-27
  • 2021-11-19
  • 2021-06-07
  • 2021-12-15
相关资源
相似解决方案