0

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 .

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

No I don't think, because the route.py is in ./app/route.py why should I add the .. Anyway changing it gave me the same error :-)
1

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

7 Comments

I don't see where on that page they say you need to use a slash. Please check my updated answer.
@rednaw Thanks a lot for your answer, but if use your method : web: gunicorn app.route:app I will have this error ImportError: No module named app.route.
Well, that's a step closer to the solution. Previously you had the error "Import by filename is not supported" because you used a filename instead of a python module name. Now you have "No module named app.route", that means Python can't find the module. Are you sure you are pointing to the right module? Are you sure it's in your pythonpath?
I added route.py yo PYTHONPATH by doing :PYTHONPATH=$PYTHONPATH:/home/myHome/myApp/app/route.py ; export PYTHONPATH. Yes I am pointing to the right module which is route.py (my WSGI). Check my ls output on @Michael answer, may be it can help .
a path in the $PYTHONPATH variable should be a directory, not a file. I think you should put it to /home/myHome/myApp/ because relative to THAT directory, python can reach app/route.py through app.route.
|
0

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?

2 Comments

$ ls -a : . .. app foo.log .git .gitignore Procfile .project .pydevproject requirements.txt .settings venv But it is ok since I found a solution and I posted it .
$ ls -a on app output's : . .. foo.log forms.py forms.pyc json README.md route.py static templates
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.