首页 > 解决方案 > 无法在heroku中运行烧瓶

问题描述

每当我在 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

这是我的烧瓶代码


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

标签: pythonflaskheroku

解决方案


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

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

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


推荐阅读