“500 internal server error” 当使用由AWS Elastic Beanstalk部署的Flask应用程序时。

huangapple go评论59阅读模式
英文:

"500 internal servor error" when using a Flask application deployed by AWS Elastic Beanstalk

问题

主页渲染正常,但当我点击一个按钮(提交)时,会跳转到另一个端点,此时页面未能正确渲染,而是出现错误提示:“服务器遇到内部错误,无法完成您的请求。可能是服务器过载或应用程序中存在错误。”

我尝试参考了各种来源,但未能找到解决方案。

英文:

Homepage of my Flask application is rendered correctly, but the issue arises when I click a button (submit) which takes me to another endpoint where instead of rendering that page, I get an error saying, "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application."

I tried to referring to various sources, but couldn't come up with a solution

答案1

得分: 0

几个小时后,我解决了这个问题,有2个问题:

  1. 在我的 Python 文件(predict_pipeline.py)中指定的路径:使用反斜杠('')来分隔目录,这是 Windows 中文件路径的约定。然而,在 AWS Elastic Beanstalk 上部署应用程序时,底层操作系统是 Linux,它使用正斜杠('/')。

解决方法: 使用 os.path.join() 修改文件路径,这是一种平台无关的方法,用于连接目录和文件名。将 "artifacts/model.pkl" 修改为 os.path.join("artifacts", "model.pkl")

  1. 我们 Flask 应用程序中使用的 scikit-learn==1.3.0 版本与 Elastic Beanstalk 使用的 scikit-learn==1.2.2 版本不匹配。

解决方法: 在我们项目目录中的 requirements.txt 文件中指定 scikit-learn==1.2.2,然后使用 pip install -r requirements.txt 安装它。

英文:

After several hours, I resolved it and there were 2 issues:

  1. The path specified in my python file (predict_pipeline.py): Used backslashes (‘\’) to separate the dirs, which is the convention for file paths in Windows. However, when deploying application on AWS Elastic Beanstalk, the underlying operating system in Linux which uses forward slashes (‘/’).

Sol: modify the file paths using os.path.join(), which is a platform independent way of joining directory and file names. Change “artifacts/model.pkl” to os.path.join(“artifacts”, “model.pkl”)

  1. The version of scikit-learn==1.3.0 used in our flask application doesn’t match with the scikit-learn==1.2.2 version used by Elastic Beanstalk.

Sol: change scikit-learn version in our virtual environment by specifying scikit-learn==1.2.2 in the requirements.txt file in our project directory and install it using pip install -r requirements.txt

huangapple
  • 本文由 发表于 2023年7月6日 20:33:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定