解决办法: 在open函数里面加一个encoding=‘UTF-8’ with open("login.html", "r", encoding='UTF-8') as f: data = f.read() 或者:将读取形式改为“rb” with open("login.html", "rb") as f: data = f.read()