我正在开发一个基于 Flask 的 Web 应用程序,用户可以上传图像以使用机器学习模型进行预测。上传的图像存储在本地目录中,并使用预先训练的模型进行预测。然而,当我按下预测按钮时 是什么导致了这个 UnicodeEncodeError? 如何解决此问题以确保我的应用程序能够正确处理图像上传和预测? 是否有在 Flask 环境中处理字符编码的最佳实践,尤其是在 Windows 上?
@app.route('/uploadimage', methods=['GET', 'POST'])
def upload_image():
file = request.files['my_image']
# Get the prediction
predicted_label = predict_label(img_path)
# Return the predicted label with a flash message
flash(f"Prediction: {predicted_label}", "success")
os.remove(img_path) # Remove the temporary file after processing
return render_template('uploadimage.html') # For GET request, render the form
即使我设置了环境变量“UTF-8”,我仍然收到此错误 错误
文件“C:\ Users \ Subha \ AppData \ Local \ Programs \ Python \ Python311 \ Lib \ site-packages \ keras \ src \ utils raceback_utils.py”,第122行,在error_handler中 从 None 引发 e.with_traceback(filtered_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“C:\ Users \ Subha \ AppData \ Local \ Programs \ Python \ Python311 \ Lib ncoding