gbk codec can't encode character问题解决 Posted on 2020-03-20 编码问题无论是做爬虫还是做对话系统,都免不了要进行数据处理以及从文件中读取数据。读取中文比较麻烦,会出各种编码错误。当出现'gbk' codec can't encode character***时,解决方案如下: 123456import sysimport iosys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')with open(file_name,encoding='utf-8') as f: line = f.readline() print(line)