python - 无法在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
解决方案
在 Procfile 中,您设置的端口 ( 33507
) 将不起作用,您需要使用PORT
Heroku 提供的端口。
您的代码是正确的(使用int(os.environ.get("PORT", 33507))
但 Procfile 应该以不同的方式设置端口
web: waitress-serve --host='0.0.0.0' --port=$PORT main:create_app
您已经listen
在 Procfile 中使用过,我认为使用$PORT
而不是硬编码 33507时它也可以正常工作
推荐阅读
- postgresql - 无法通过 pgadmin 使用 docker compose 登录到 Postgres
- azure - API 连接因“禁止”而失败
- python - 从 pyspark 会话中获取 hive 和 hadoop 版本
- android - 如何将方法通道添加到 Flutter 片段
- ios - 使用导航控制器的自定义转换的基本问题
- memory-management - 当您丢失页面目录的虚拟地址时会发生什么?
- sql-server - 如果字段索引是常量,连接可以有效地忽略它们吗?
- ruby-on-rails - Ruby on rails教程第9.3.1章练习
- typescript - 将主题应用于材质 UI 菜单组件
- python - 为什么我的阅读器不能从文件中导入 basereader?