【问题标题】:Flask app dont start on heroku serverFlask 应用程序不会在 heroku 服务器上启动
【发布时间】:2013-11-14 06:39:04
【问题描述】:

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

这是我的应用程序代码(我知道这是一个块,但我无法将其拆分为文件):

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

【问题讨论】:

  • 你使用外部mysql服务器吗?

标签: python heroku flask flask-restless


【解决方案1】:

实际上是否有一个名为web 的正在运行的测功机?看来你可能忘了scale your web dyno

在您的 Procfile 中添加这样的条目:

heroku ps:scale web=1

你可以使用

heroku ps

确认您的web dyno 正在运行。

【讨论】:

【解决方案2】:

1.Procfile 应该没有任何扩展名。

2.Procfile的内容应该是:web: gunicorn app:app --preload

注意:通常--preload在size比较大的时候用。

【讨论】:

    【解决方案3】:

    我运行下面的命令来解决这个问题,

    heroku ps:scale web=1 --app YourApp
    

    在 cli bash 上运行它,例如 linux、wsl、mac 或 powershell。 注意:如果你在工人中运行;你应该改成worker=1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 2017-04-02
      • 2011-03-31
      • 2019-04-05
      • 2013-10-16
      • 2016-10-18
      相关资源
      最近更新 更多