报错解决:'gbk' codec can't encode character u'\xc3' in position 0: illegal multibyte sequence

报错解决:'gbk' codec can't encode character u'\xc3' in position 0: illegal multibyte sequence

  • 当python解码时出现报错illegal multibyte sequence
json.dumps(s, indent = 4,cls = FormatEncoder, ensure_ascii = False).encode("iso-8859-1").decode('gb18030').encode    ('utf8')
  • 解决方法:
    添加ignore,忽略报错
    json.dumps(s, indent = 4,cls = FormatEncoder, ensure_ascii = False).encode("iso-8859-1").decode('gb18030',errors='ignore').encode ('utf8')
  • with/open语句
open('c:/xxx/test.txt',errors='ignore')
with open('c:/xxx/test.txt',errors='ignore') as f:

你可能感兴趣的:(报错解决)