错误背景:
with open("index.html","r") as file: # 这里的file表示打开文件的对象
file_data = file.read() # 读取文件的数据
异常信息
UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 112: illegal multibyte sequence
错误原因
文件中包含中文,需要加上编码格式
解决办法
with open("index.html","r",encoding="utf-8") as file: # 这里的file表示打开文件的对象
file_data = file.read() # 读取文件的数据