python - Flask 应用程序不在 heroku 服务器上启动

标签 python heroku flask flask-restless

我正在尝试使用 Heroku 部署 Flask 应用程序。这是简单的 API。在本地与工头一起工作很好,但在 heroku 上启动时出现错误(日志在下面)。

这是我的应用程序代码(我知道它只是在一个 block 中查找,但我无法将其拆分为文件):

import flask
import flask.ext.sqlalchemy
import flask.ext.restless

app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:password@server/db'
db = flask.ext.sqlalchemy.SQLAlchemy(app)


from sqlalchemy import Column, Integer, String, ForeignKey,\
    Date, DateTime, Boolean, Float


class fruits(db.Model):
    __tablename__ = 'fruits'
    id = Column(Integer, primary_key=True)
    name = Column(String(50),nullable=False)
    calories = Column(Integer, nullable=False)
    amount = Column(Integer, nullable=False)
    unit = Column(String(10),nullable=False)
    url = Column(String(100),nullable=True)


@app.route('/')
def hello_world():
    return 'Hello World!'


# Create the database tables.
db.create_all()

# Create the Flask-Restless API manager.
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)

# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
manager.create_api(fruits, methods=['GET', 'POST', 'DELETE'])
manager.create_api(tmp, methods=['GET', 'POST', 'DELETE'])


# start the flask loop

if __name__ == '__main__':
        import os  
        port = int(os.environ.get('PORT', 33507)) 
        app.run(host='0.0.0.0', port=port)

这是 heroku 日志:

at=error code=H14 desc="No web processes running" method=GET path=/ host=blooming-taiga-1210.herokuapp.com fwd="188.33.19.82" dyno= connect= service= status=503 bytes=

和我的 Procfile:

web: python __init__.py

最佳答案

是否真的有一个名为 web 的正在运行的测功机?看起来你可能有 scaled your web dynos down to 0 :

使用这样的 ps:scale 命令将您的 web dynos 缩放到至少 1:

heroku ps:scale web=1

你可以使用

heroku ps

确认您的 web dyno 正在运行。

关于python - Flask 应用程序不在 heroku 服务器上启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19754262/

相关文章:

javascript - 动态填充多个(不止一个)下拉选项/选项(Flask、python、Ajax)

javascript - 如何从获取响应中获取gif

javascript - 在 node.js 中使用工作进程/后台进程与异步调用

python - 如何在 Flask 路由中保留前导零

python - Pandas 更新 dataframe1 中的列 A,其中 dataframe1 列 2 与 dataframe2 列匹配

python - 查找值为真的 boolean 数组的索引

python - 在atom编辑器中导入matplotlib.pyplot

python - 用 numpy 拟合数据

node.js - 如何将 nestjs 应用程序( typescript )部署到 heroku?

ios - Swift iOS - 如何将 Firebase token 发送到 Heroku 上的 Https URL?