[英]"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.我第一次创建了一个非常轻的 python/flask 应用程序,它完全写在一个文件中。 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:
我尝试创建一个轻量级 API 并使其可从终端(curl 等)访问,但在部署它并尝试检索数据后出现以下错误:
desc="No web processes running" .....
The app folder structure:应用程序文件夹结构:
FolderName:文件夹名称:
app.py
Procfile
requirements.txt
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 .我是如何部署的: 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
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
我是构建 API 的新手
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 1. 在我的终端中运行
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
2. 由于我没有单独的 wsgi 文件,所以在我的 procfile 中,我输入了文件名
gunicorn app:app
,而不是 wsgi
3. Added gunicorn
to my requirements file 3.在我的需求文件中添加了
gunicorn
Now the curl command works from any terminal现在 curl 命令可以从任何终端运行
The Procfile should look like this: Procfile 应如下所示:
web: <command>
web: gunicorn wsgi:app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.