UnicodeEncodeError:“charmap”编解码器无法对位置 19-38 中的字符进行编码:字符映射到 <undefined>

问题描述 投票:0回答:0

我正在开发一个基于 Flask 的 Web 应用程序,用户可以上传图像以使用机器学习模型进行预测。上传的图像存储在本地目录中,并使用预先训练的模型进行预测。然而,当我按下预测按钮时 是什么导致了这个 UnicodeEncodeError? 如何解决此问题以确保我的应用程序能够正确处理图像上传和预测? 是否有在 Flask 环境中处理字符编码的最佳实践,尤其是在 Windows 上?

==app.py====

@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

python machine-learning flask keras unicode
© www.soinside.com 2019 - 2024. All rights reserved.