python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 30: illegal multibyte sequence

  昨天用用python3写个日志文件,结果报错UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 30: illegal multibyte sequence

  具体代码是:

  with open(fileName, 'a') as f:

    f.write(message)

  后来改成如下:

  with open(fileName, 'a',encoding='utf-8') as f:

    f.write(message)

  就可以了。还是编码的问题

上一篇:python3 UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f9e0' in position 230: illegal multibyte sequence


下一篇:spring 以Ant Build方式运行build.xml文件,报warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds 的解决办法