【问题标题】:"No web processes running" error when trying to reach my Heroku app (Python/Flask)尝试访问我的 Heroku 应用程序(Python/Flask)时出现“没有运行 Web 进程”错误
【发布时间】:2020-07-02 16:51:48
【问题描述】:

我第一次创建了一个完全编写在一个文件中的非常轻量级的 python/flask 应用程序。 我尝试创建一个轻量级 API 并使其可从终端(curl 等)访问,但在部署它并尝试检索数据后出现以下错误:

    desc="No web processes running" .....

应用文件夹结构:

文件夹名称:

app.py Procfile requirements.txt

现在他们每个人都包含什么:

app.py

    import flask
    import datetime
    import requests
    import json


    app = flask.Flask(__name__)


    @app.route('/covidData', methods=('GET', 'POST'))
    def get_data():

        country_input = flask.request.args.get('country')
        date_input = flask.request.args.get('date')
        date_split = date_input.split("-")
        date = datetime.datetime(int(date_split[2]),  int(date_split[0]), int(date_split[1])).strftime('%m-%d-%Y')

        data = requests.get('https://covid19.mathdro.id/api/daily/' + date)
        processed_data = data.json()

        for country in processed_data:
            if country['countryRegion'] == country_input:
                target_country = country

        requested_data = {"Country": target_country['countryRegion'], "Cases": target_country["confirmed"], "Recovered": target_country["recovered"]}

        return flask.jsonify(requested_data)


    if __name__ == '__main__':
        app.run(port=5000)

过程文件:

    gunicorn wsgi:app

要求:

    requests==2.22.0
    Flask==1.1.1

我是如何部署的: 1.git初始化 2.heroku登录 3.创建了一个Procfile 4. heroku 应用程序:创建 5. 混帐添加。 6. git commit -m "heroku 部署" 7. git push heroku master

然后,我尝试从本地终端检索数据:

    curl -X POST "https://covid-19-2020-api.herokuapp.com/covidData?country=Israel&date=03-20-2020"

并得到以下错误:

    heroku[router]: at=error code=H14 desc="No web processes running" method=POST path="/covidData?country=Israel&date=03-20-2020" host=covid-19-2020-api.herokuapp.com request_id=8b56257e-4c4f-46df-b8d9-ee487a4a5480 fwd="185.175.33.226" dyno= connect= service= status=503 bytes= protocol=https

可能是什么问题,任何建议,方向将不胜感激!我是构建 API 的新手

谢谢!

【问题讨论】:

    标签: python api flask heroku


    【解决方案1】:

    好的,我找到了解决方案。它分三个步骤完成:
    1. 在我的终端中运行heroku ps:scale web=1 - Getting Started on Heroku with Python
    2. 由于我没有单独的 wsgi 文件,所以在我的 procfile 中,而不是 wsgi,我输入了文件的名称gunicorn app:app
    3. 在我的需求文件中添加了gunicorn

    现在 curl 命令可以在任何终端运行

    【讨论】:

    • 谢谢谢谢谢谢!在一个非常旧的应用程序的新版本发布后,我遇到了这个问题,根本无法弄清楚。但是当我读到你的答案时,我突然想起我在大约 7 个月前将测功机缩小到 0!将测功机缩放回 1 就行了!
    • 嘿! :) 很高兴听到它对您有所帮助!祝你好运!
    【解决方案2】:

    Procfile 应该如下所示:

    web: <command>
    web: gunicorn wsgi:app
    

    reference example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-18
      • 2012-12-19
      • 1970-01-01
      • 2018-09-02
      • 2012-12-17
      • 2013-04-30
      • 1970-01-01
      • 2022-12-20
      相关资源
      最近更新 更多