繁体   English   中英

尝试访问我的 Heroku 应用程序(Python/Flask)时出现“没有网络进程运行”错误

[英]"No web processes running" error when trying to reach my Heroku app (Python/Flask)

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

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

应用程序文件夹结构:

文件夹名称:

app.py Procfile requirements.txt

现在他们每个人都包含:

应用程序

    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 init 2. heroku login 3. 创建一个 Procfile 4. heroku apps:create 5. git add 。 6. git commit -m "heroku deployment" 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 的新手

谢谢!

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

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

Procfile 应如下所示:

web: <command>
web: gunicorn wsgi:app

参考例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM