gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 19:35:59 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com