简体   繁体   中英

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

First time I created a very light python/flask application that is fully written in one file. I tried to create a light API and make it accessible from the terminal (curl, etc.) and got the following error after I deployed it and tried to retrieve the data:

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

The app folder structure:

FolderName:

app.py Procfile requirements.txt

Now what each of them contains:

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)

Procfile:

    gunicorn wsgi:app

requirements:

    requests==2.22.0
    Flask==1.1.1

How I deployed: 1. git init 2. heroku login 3. created a Procfile 4. heroku apps:create 5. git add . 6. git commit -m "heroku deployment" 7. git push heroku master

Then, I try to retrieve the data from my local terminal:

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

And get the following Error:

    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

What might be the problem, any advice, directions will be highly appreciated! I am newby in building APIs

Thank you!

Ok, I found the solution. It was done in three steps:
1. in my terminal a ran heroku ps:scale web=1 - Getting Started on Heroku with Python
2. As I don't have a separate wsgi file, in my procfile, instead of wsgi, I put the name of the file gunicorn app:app
3. Added gunicorn to my requirements file

Now the curl command works from any terminal

The Procfile should look like this:

web: <command>
web: gunicorn wsgi:app

reference example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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