4m1nh4j1
4m1nh4j1

Reputation: 4356

Flask/Python application failed to start before deployment on Heroku

I would like to deploy a Flask (python) app on Heroku, I did it before without any problem . But now, I don't know what is the problem .

The problem is here, When I enter the following command to test the local server :

foreman start

I have this error :

foreman start
12:01:53 web.1  | started with pid 6055
12:01:53 web.1  | 2013-12-25 12:01:53 [6058] [INFO] Starting gunicorn 18.0
12:01:53 web.1  | 2013-12-25 12:01:53 [6058] [INFO] Listening at: http://0.0.0.0:5000 (6058)
12:01:53 web.1  | 2013-12-25 12:01:53 [6058] [INFO] Using worker: sync
12:01:53 web.1  | 2013-12-25 12:01:53 [6063] [INFO] Booting worker with pid: 6063
12:01:53 web.1  | 2013-12-25 12:01:53 [6063] [ERROR] Exception in worker process:
12:01:53 web.1  | Traceback (most recent call last):
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
12:01:53 web.1  |     worker.init_process()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
12:01:53 web.1  |     self.wsgi = self.app.wsgi()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
12:01:53 web.1  |     self.callable = self.load()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
12:01:53 web.1  |     return self.load_wsgiapp()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
12:01:53 web.1  |     return util.import_app(self.app_uri)
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
12:01:53 web.1  |     __import__(module)
12:01:53 web.1  | ImportError: Import by filename is not supported.
12:01:53 web.1  | Traceback (most recent call last):
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
12:01:53 web.1  |     worker.init_process()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
12:01:53 web.1  |     self.wsgi = self.app.wsgi()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
12:01:53 web.1  |     self.callable = self.load()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
12:01:53 web.1  |     return self.load_wsgiapp()
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
12:01:53 web.1  |     return util.import_app(self.app_uri)
12:01:53 web.1  |   File "/home/myhome/myApp/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
12:01:53 web.1  |     __import__(module)
12:01:53 web.1  | ImportError: Import by filename is not supported.
12:01:53 web.1  | 2013-12-25 12:01:53 [6063] [INFO] Worker exiting (pid: 6063)
12:01:53 web.1  | 2013-12-25 12:01:53 [6058] [INFO] Shutting down: Master
12:01:53 web.1  | 2013-12-25 12:01:53 [6058] [INFO] Reason: Worker failed to boot.
12:01:53 web.1  | exited with code 3
12:01:53 system | sending SIGTERM to all processes
SIGTERM received

My Procfile is :

web: gunicorn app/route:app

And I am using this main :

if __name__ == '__main__':
    import logging
    from logging.handlers import RotatingFileHandler
    handler = RotatingFileHandler('foo.log', maxBytes=10000, backupCount=1)
    handler.setLevel(logging.INFO)
    app.logger.addHandler(handler)
    if TODAY != cache.config['CACHE_ARGS'] :
        with app.app_context():
            cache.clear()
    port = int(os.environ.get('PORT', 33507))
    app.run(debug = True, host='0.0.0.0', port=port)

When I run the app on the browser (0.0.0.0:33507) it works perfectly .

Upvotes: 0

Views: 4589

Answers (4)

Vineeth Guna
Vineeth Guna

Reputation: 398

Your Procfile should be

web: gunicorn app.route:app

And make sure that your folder app which contains route.py is a package which means the app folder should contain __init__.py to make app folder as package

Upvotes: 0

Michael
Michael

Reputation: 1197

Where is your Procfile located? It should be in the main directory. Can you post your directory structure? Or do you have this project on Github?

Upvotes: 0

4m1nh4j1
4m1nh4j1

Reputation: 4356

Well I found something helpful here : http://ryaneshea.com/lightweight-python-apps-with-flask-twitter-bootstrap-and-heroku

The Procfile should look like this :

web: python app/route.py

Upvotes: 1

gitaarik
gitaarik

Reputation: 46270

Shouldn't this:

web: gunicorn app/route:app

be:

web: gunicorn app.route:app

Gunicorn github page says:

Basic usage:

$ gunicorn [OPTIONS] APP_MODULE

Where APP_MODULE is of the pattern $(MODULE_NAME):$(VARIABLE_NAME). The module name can be a full dotted path. The variable name refers to a WSGI callable that should be found in the specified module.

https://github.com/benoitc/gunicorn#gunicorn

Upvotes: 2

Related Questions