解决UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte问题

早上在用Flask框架时出现了这个问题,我在源代码里写的是

@app.route('/hello')
def hello():
   return render_template('index.html')

然后打开网页,出现问题,报的错是:

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte

我在网上查阅了资料,这个报错主要是因为我的网站index.html这个文件的16进制开头是FF FE。

文件的16进制格式开头的FF FE或者FE FF是Windows平台下特有的BOM开头,不要在文件的开头使用。

解决办法是用notepad++或者sublime text等文本剪辑器打开文件,以没有BOM的utf-8编码格式保存。

最后,欢迎大家关注我的GitHub:zhang0peter

发布了502 篇原创文章 · 获赞 145 · 访问量 48万+

猜你喜欢

转载自blog.csdn.net/zhangpeterx/article/details/83419058