Unable to run flask in heroku
·
Answer a question
I'm getting app crash whenever I run my flask application in heroku
**This the log I get**
2021-05-07T08:16:12.395679+00:00 heroku[web.1]: Starting process with command `waitress-serve --listen=0.0.0.0:33507 main:create_app`
2021-05-07T08:16:16.056323+00:00 app[web.1]: INFO:waitress:Serving on http://0.0.0.0:33507
2021-05-07T08:16:23.146656+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=malibu-luxury.herokuapp.com request_id=c81fd09c-29e6-48ed-bb32-73ee6f5f29bc fwd="49.205.79.67" dyno= connect= service= status=503 bytes= protocol=https
2021-05-07T08:17:13.001979+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-05-07T08:17:13.050236+00:00 heroku[web.1]: Stopping process with SIGKILL
2021-05-07T08:17:13.142541+00:00 heroku[web.1]: Process exited with status 137
2021-05-07T08:17:13.216370+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-07T08:17:15.352721+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=malibu-luxury.herokuapp.com request_id=fd3e869a-7515-45c3-ace8-a322b6969c65 fwd="49.205.79.67" dyno= connect= service= status=503 bytes= protocol=https
This is my flask code
import MySQLdb.cursors
import re
import os
from importlib import reload
def get_port():
return int(os.environ.get("PORT", 33507))
return (delta.days)
def create_app():
app = Flask(__name__)
.
.
.
app.run(debug=True,host='0.0.0.0',port=get_port())
return app
This is my procfile web: waitress-serve --listen=0.0.0.0:33507 main:create_app
Answers
In the Procfile you are setting the port (33507) which will not work, you need to use the PORT provided by Heroku.
You code is correct (using int(os.environ.get("PORT", 33507)) but the Procfile should set the port differently
web: waitress-serve --host='0.0.0.0' --port=$PORT main:create_app
You have used listen in your Procfile, I think it can work as well when using $PORT instead of hardcoding 33507
更多推荐

所有评论(0)