无法在heroku中运行烧瓶

时间:2021-05-07 08:36:13

标签: python flask heroku

每当我在 heroku 中运行我的 Flask 应用程序时,我都会遇到应用程序崩溃

**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

这是我的烧瓶代码


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  

这是我的记录 web: waitress-serve --listen=0.0.0.0:33507 main:create_app

1 个答案:

答案 0 :(得分:0)

在 Procfile 中您设置的端口 (33507) 不起作用,您需要使用 Heroku 提供的 PORT
您的代码是正确的(使用 int(os.environ.get("PORT", 33507)) 但 Procfile 应该以不同的方式设置端口

web: waitress-serve --host='0.0.0.0' --port=$PORT main:create_app

您在 Procfile 中使用了 listen,我认为使用 $PORT 而不是硬编码 33507 时它也可以工作