【问题标题】:Flask App Error while deploying to Heroku at=error code=H10 desc="App crashed" method=GET path="/"Flask App 部署到 Heroku 时出错 at=error code=H10 desc="App crashed" method=GET path="/"
【发布时间】:2020-04-28 00:28:33
【问题描述】:

示例烧瓶应用程序在 Heroku 中部署时出现错误 at=error code=H10 desc="App crashed" 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()'''

Poc文件

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

关注了一些博客,但无法解决。请帮忙

【问题讨论】:

    标签: python-3.x heroku flask


    【解决方案1】:

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

    web: gunicorn --bind 0.0.0.0:$PORT flaskapp:app
    

    【讨论】:

    • 嗨,即使我在 Procfile 中添加了绑定端口,我也是同样的问题。应用程序仍然崩溃。你能告诉我为什么会这样吗?
    【解决方案2】:

    您的procfile 中有错误。

    web: gunicorn
    

    应该这样写。网页后不要留空间,它会正常工作。

    【讨论】:

      【解决方案3】:

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

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

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

      【讨论】:

        【解决方案4】:

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

        1> 打开你的终端

        2> 类型 - cd YOUR_PROJECT_DIRECTORY

        3> 类型 - pip freeze &gt; requirements.txt

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

        5> git push heroku 大师

        【讨论】:

          【解决方案5】:

          我的项目结构

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

          pip install gunicorn

          pip freeze &gt; 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

          【讨论】:

            【解决方案6】:

            确保 gunicorn 包含在 requirements.txt 文件中。

            【讨论】:

              【解决方案7】:

              在 proc 文件中 网络:gunicorn --bind 0.0.0.0:$PORT app:app 在应用程序中确认 如果 name == 'ma​​in': app.run(debug=True)

              【讨论】:

                猜你喜欢
                • 2021-10-22
                • 2015-03-01
                • 2013-03-30
                • 2018-04-09
                • 2019-07-02
                • 1970-01-01
                • 2018-07-21
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多