Flask - NameError: name 'application' is not defined

2,245 views
Skip to first unread message

Anders Ytterström

unread,
Nov 26, 2012, 12:13:07 PM11/26/12
to appfog...@googlegroups.com
Hi, I am trying to upload a site made in Flask and gunicorn seems to be the issue. Any help?

This is my requirements.txt:

PIL==1.1.7
Flask==0.8

My app is an wsgi.py file, as the documentation told me: https://docs.appfog.com/languages/python/flask

This is my output:

mylion-2:mhold andersy$ af update mhold && af restart mhold
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (1K): OK  
Push Status: OK
Stopping Application 'mhold': OK
Staging Application 'mhold': OK                                                
Starting Application 'mhold': ..
Error: Application [mhold] failed to start, logs information below.

====> /logs/staging.log <====

Requirement already satisfied (use --upgrade to upgrade): pip==1.1 in ./python/lib/python2.7/site-packages/pip-1.1-py2.7.egg
Cleaning up...
Downloading/unpacking gunicorn
  Running setup.py egg_info for package gunicorn
   
Installing collected packages: gunicorn
  Running setup.py install for gunicorn
   
    Installing gunicorn_paster script to /tmp/d20121126-27963-1521a4g/staged/python/bin
    Installing gunicorn script to /tmp/d20121126-27963-1521a4g/staged/python/bin
    Installing gunicorn_django script to /tmp/d20121126-27963-1521a4g/staged/python/bin
Successfully installed gunicorn
Cleaning up...
Requirement already satisfied (use --upgrade to upgrade): PIL==1.1.7 in /usr/lib/python2.7/dist-packages/PIL (from -r requirements.txt (line 1))
Downloading/unpacking Flask==0.8 (from -r requirements.txt (line 2))
  Running setup.py egg_info for package Flask
   
    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'examples'
    warning: no previously-included files matching '*.pyo' found under directory 'examples'
    no previously-included directories found matching 'docs/_build'
    no previously-included directories found matching 'docs/_themes/.git'
Downloading/unpacking Werkzeug>=0.6.1 (from Flask==0.8->-r requirements.txt (line 2))
  Running setup.py egg_info for package Werkzeug
   
    warning: no files found matching '*' under directory 'werkzeug/debug/templates'
    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'examples'
    warning: no previously-included files matching '*.pyo' found under directory 'examples'
    no previously-included directories found matching 'docs/_build'
Downloading/unpacking Jinja2>=2.4 (from Flask==0.8->-r requirements.txt (line 2))
  Running setup.py egg_info for package Jinja2
   
    warning: no previously-included files matching '*' found under directory 'docs/_build'
    warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
Installing collected packages: Flask, Werkzeug, Jinja2
  Running setup.py install for Flask
   
    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'examples'
    warning: no previously-included files matching '*.pyo' found under directory 'examples'
    no previously-included directories found matching 'docs/_build'
    no previously-included directories found matching 'docs/_themes/.git'
  Running setup.py install for Werkzeug
   
    warning: no files found matching '*' under directory 'werkzeug/debug/templates'
    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory 'examples'
    warning: no previously-included files matching '*.pyo' found under directory 'examples'
    no previously-included directories found matching 'docs/_build'
  Running setup.py install for Jinja2
   
    warning: no previously-included files matching '*' found under directory 'docs/_build'
    warning: no previously-included files matching '*.pyc' found under directory 'jinja2'
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'jinja2'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
Successfully installed Flask Werkzeug Jinja2
Cleaning up...
Requirement already satisfied (use --upgrade to upgrade): gunicorn in ./python/lib/python2.7/site-packages
Cleaning up...
Requirement already satisfied (use --upgrade to upgrade): PIL==1.1.7 in /usr/lib/python2.7/dist-packages/PIL (from -r requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): Flask==0.8 in /mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages (from -r requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.6.1 in /mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages (from Flask==0.8->-r requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages (from Flask==0.8->-r requirements.txt (line 2))
Cleaning up...

====> /logs/stderr.log <====

2012-11-26 17:09:19 [26863] [INFO] Starting gunicorn 0.16.1
2012-11-26 17:09:19 [26863] [DEBUG] Arbiter booted
2012-11-26 17:09:19 [26863] [INFO] Listening at: http://0.0.0.0:49921 (26863)
2012-11-26 17:09:19 [26863] [INFO] Using worker: sync
2012-11-26 17:09:19 [26867] [INFO] Booting worker with pid: 26867
2012-11-26 17:09:19 [26867] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 469, in spawn_worker
    worker.init_process()
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 99, in wsgi
    self.callable = self.load()
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 24, in load
    return util.import_app(self.app_uri)
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/util.py", line 296, in import_app
    app = eval(obj, mod.__dict__)
  File "<string>", line 1, in <module>
NameError: name 'application' is not defined
Traceback (most recent call last):
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 469, in spawn_worker
    worker.init_process()
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 99, in wsgi
    self.callable = self.load()
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 24, in load
    return util.import_app(self.app_uri)
  File "/mnt/var/vcap.local/dea/apps/mhold-0-cb1e8d415b159b57f36e8e4edccb1756/python/lib/python2.7/site-packages/gunicorn/util.py", line 296, in import_app
    app = eval(obj, mod.__dict__)
  File "<string>", line 1, in <module>
NameError: name 'application' is not defined
2012-11-26 17:09:19 [26867] [INFO] Worker exiting (pid: 26867)
2012-11-26 17:09:20 [26863] [INFO] Shutting down: Master
2012-11-26 17:09:20 [26863] [INFO] Reason: Worker failed to boot.

Help appreciated!

ryan

unread,
Nov 26, 2012, 1:34:42 PM11/26/12
to appfog...@googlegroups.com
Hey Anders,

Thanks for reaching out to us. It looks like this error may be stemming from the wsgi.py file. It seems that in your file you have the name line set to:

     app = Flask(__name__)

In the documentation that you mentioned above, it had the line set to read:

     application = app = Flask(__name__)

Go ahead and try changing that line up in your wsgi.py file and let us know if that helps.

Cheers!

Ryan, AppFog

Anders Ytterström

unread,
Nov 27, 2012, 12:21:20 AM11/27/12
to appfog...@googlegroups.com
Hi,

Thank you for a kind and fast answer! You are indeed correct, I missed that my Flask object must be named 'application'.

It now works fine.

/ay
Reply all
Reply to author
Forward
0 new messages