部署到Heroku时出现Flask应用程序错误,错误代码为=错误代码= H10 desc =“应用程序崩溃”,方法= GET路径=“ /”

时间:2020-01-10 10:53:31

标签: python-3.x heroku flask

示例烧瓶应用程序在Heroku中进行部署时,出现错误at =错误代码= H10 desc =“应用程序崩溃” method = GET path =“ /”。

Flaskapp.py

from flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
    return "<h1> Deployed to Heroku</h1>"


if __name__ == "__main__":
    app.run()'''

Pocfile

web : gunicorn flaskapp:app

requirements.txt

Click==7.0
Flask==1.1.1
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
Werkzeug==0.16.0

下面的错误日志

2020-01-10T10:35:14.658092+00:00 heroku[web.1]: Starting process with command `: gunicorn flaskapp:app`
2020-01-10T10:35:16.404755+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-10T10:35:16.381754+00:00 heroku[web.1]: Process exited with status 0
2020-01-10T10:35:19.000000+00:00 app[api]: Build succeeded
2020-01-10T10:35:38.654704+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=flaskapp-te.herokuapp.com request_id=6712472d-a734-4720-b152-1e2716844c41 fwd="137.97.4.98" dyno= connect= service= status=503 bytes= protocol=https
2020-01-10T10:35:39.689766+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=flaskapp-te.herokuapp.com request_id=89a26803-5b09-4a94-99a2-5b0d154d7797 fwd="137.97.4.98" dyno= connect= service= status=503 bytes= protocol=https

关注了一些博客,无法解决。请协助

5 个答案:

答案 0 :(得分:4)

将以下post中提到的Procfile修改为

-3210

答案 1 :(得分:0)

您的 procfile 中存在错误。

web: gunicorn

应该是这样写的。不要在 web 后面留空格,它会正常工作。

答案 2 :(得分:0)

1 年零 2 个月后。正如其他答案所指出的,Procfile 中存在一个问题。我个人认为不需要 --bind 0.0.0.0:$PORT,因为我的应用程序在没有这部分代码的情况下运行良好 - 但我不假装知道它的目的是什么。对于这个特定问题,Procfile 中的空间是问题所在,我发现 this tutorial 在解决我自己的 Procfile 问题时很有帮助。

但是,我想为那些在知道 Procfile 不是问题但仍然收到 h10 错误的情况下发现此问题的人添加以下内容。

对于那些专门针对 h10 错误发现此问题的人,并且您知道您的 Procfile 是正确的,请确保您正在阅读完整的日志。我发现隐藏在混乱中的是说明未找到某些模块的行。显然,我的 pip 安装不完整或不在我的虚拟 env 文件夹中。并不是所有丢失的安装都会显示出来。每次推送可能会出现需要安装并添加到您的 requirements.txt 文件的新模块。多次推动以解决每个缺失的项目,最终我的应用开始在 Heroku 上正确运行。

答案 3 :(得分:0)

我遇到了同样的错误,与上次您可能在 pip 中安装了一些新包并将它们导入到 app.py 文件中的情况相比。只需重新生成您的 requirements.txt 文件并再次将其推送到 heroku master,它就会运行良好

1> 打开你的终端

2> 类型 - cd YOUR_PROJECT_DIRECTORY

3> 类型 - pip freeze > requirements.txt

4> 将您的代码推送到您的存储库。

5> git push heroku master

答案 4 :(得分:0)

我的项目结构

My Project Structure 创建名为 Procfile 的文件(不需要扩展名)- 在其中写入以下行 web: gunicorn main:app 其中“main”是提及app = create_app()的文件名

pip install gunicorn

pip freeze > requirements.txt

再创建一个名为 runtime.txt 的文件,其中包含以下行 python-3.9.2 (提供您项目的相应python版本)

<块引用>

Heroku 部分:使用 gitbashvscode 控制台一一运行以下命令

heroku login

git init

git add .

git commit -am "Initial Commit"

git push heroku main