Flask app dont start on heroku server
Asked Answered
S

3

13

I'm trying to deploy a Flask app with Heroku. It's simple API. Works great local with foreman but I get error (log is below) when starts on heroku.

This is my app code (I know it's but looking in one block, but I have problems to split it to files):

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)

This is heroku log:

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=

and my Procfile:

web: python __init__.py
Steiner answered 3/11, 2013 at 14:56 Comment(1)
Do you use external mysql server?Agenda
D
29

Is there actually a running dyno called web? It looks like you might have scaled your web dynos down to 0:

Use a ps:scale command like this to scale your web dynos to at least 1:

heroku ps:scale web=1

You can use

heroku ps

to confirm that your web dyno is running.

Durstin answered 3/11, 2013 at 16:30 Comment(3)
It's works when I do it in console, no in Procfile. Thanks!Steiner
Holy hell, I can't believe this isn't in their deploy docs anywhere.Disavowal
This is done by default, according to Heroku: devcenter.heroku.com/articles/procfile#scaling-a-process-typePearman
B
1

1.Procfile should be without any extension.

2.Content of Procfile should be: web: gunicorn app:app --preload

Note:usually --preload is used when the size is more.

Busby answered 22/12, 2020 at 22:57 Comment(0)
S
0

i run below command for fix this problem,,

heroku ps:scale web=1 --app YourApp

run it on cli bash like linux, wsl, mac, or powershell. note: if you run in worker; you should change to worker=1

Sd answered 19/12, 2021 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.