开向幼儿园的车 2022-04-04 11:44 采纳率: 90%
浏览 3484
已结题

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

在使用python flask 时,网页显示不出图片,只运行html文件可以,但运行py文件就不行,于是上网查资料发现不能直接贴上去
py 文件:
from flask import Flask,render_template

app = Flask(name)

def return_img_stream(image_loca_path): #向前端显示图片时使用,把图片转换成数据流
import base64
image_stream = ''
with open(image_loca_path,"r",encoding="UTF-8") as f: # 图片格式有问题
image_stream = f.read()
image_stream = base64.b64encode(image_stream)
return image_stream

@app.route("/")
def index():
image_path = "templates/images/bc.png"
image_stream = return_img_stream(image_path)
return render_template("index.html",img_stream=image_stream)

if name == "main":
app.run(host="0.0.0.0",debug=True)

html文件:

<title> my first python web </title> no way append

报错提示:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

img

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 4月13日
      • 已采纳回答 4月5日
      • 创建了问题 4月4日

      悬赏问题

      • ¥50 请求关于BBS数据集的资源分享
      • ¥15 设计一份接口自动化测试报告
      • ¥15 手机安装kali后ifconfig 提示错误
      • ¥15 用C++求矩阵的特征值
      • ¥30 求解答(自动忽略本括号内容)
      • ¥15 根据C语言小型成绩管理系统画一个流程图
      • ¥15 关于#c语言#的问题:帮我分析一下一下代码中我用橙色笔圈住的部分
      • ¥15 Javaweb的增删改查
      • ¥30 用eclipse和sqlserver做
      • ¥15 unity 发布 kinect 项目后失去焦点的问题