windows文系统编码的文件,编码为gbk,python操作时设置读取时编码为gbk
读取文件操作时需要读取编码类型为utf-8,python操作时需要设置读取utf-8
解决方法:在文件的右括号前面加上: , encoding='UTF-8'
with open('./template/index.html', 'r') as file:file_data = file.read()
这时报错:'gbk' codec can't decode byte 0xaa in position 223: illegal multibyte sequence
修改代码为以下即可解决
with open('./template/index.html', 'r', encoding='utf-8') as file:file_data = file.read()