简体   繁体   中英

gunicorn causing errors in heroku

I just pushed my app to heroku for the first time but keep getting an "Application Error" when I visit the page.. I'm not familiar with heroku and can't seem to find any reference in the help/dev center links.

Going to the heroku logs I get this:

C:\Users\XXX\Desktop\xxxxx.folder>heroku logs
2013-10-14T02:32:18.578976+00:00 heroku[api]: Enable Logplex by EMAIL@email.com
2013-10-14T02:32:18.597277+00:00 heroku[api]: Release v2 created by EMAIL@email.com
2013-10-14T02:32:46+00:00 heroku[slug-compiler]: Slug compilation started
2013-10-14T02:33:10.309086+00:00 heroku[api]: Scale to web=1 by EMAIL@email.com
2013-10-14T02:33:10.356490+00:00 heroku[api]: Deploy 9edccd8 by EMAIL@email.com
2013-10-14T02:33:10.375197+00:00 heroku[api]: Release v3 created by EMAIL@email.com
2013-10-14T02:33:10+00:00 heroku[slug-compiler]: Slug compilation finished
2013-10-14T02:33:14.369318+00:00 heroku[web.1]: Starting process with command `gunicorn xxxxx:app`
2013-10-14T02:33:15.336306+00:00 app[web.1]: 2013-10-14 02:33:15 [2] [INFO] Starting gunicorn 18.0
2013-10-14T02:33:15.337257+00:00 app[web.1]: 2013-10-14 02:33:15 [2] [INFO] Listening at: http://0.0.0.0:36245 (2)
2013-10-14T02:33:15.337821+00:00 app[web.1]: 2013-10-14 02:33:15 [2] [INFO] Using worker: sync
2013-10-14T02:33:15.354973+00:00 app[web.1]: 2013-10-14 02:33:15 [7] [INFO] Booting worker with pid: 7
2013-10-14T02:33:15.360482+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
2013-10-14T02:33:15.360482+00:00 app[web.1]:     self.callable = self.load()
2013-10-14T02:33:15.360482+00:00 app[web.1]: Traceback (most recent call last):
2013-10-14T02:33:15.360482+00:00 app[web.1]: 2013-10-14 02:33:15 [7] [ERROR] Exception in worker process:
2013-10-14T02:33:15.360482+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
2013-10-14T02:33:15.360482+00:00 app[web.1]:     worker.init_process()
2013-10-14T02:33:15.360482+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2013-10-14T02:33:15.360482+00:00 app[web.1]:     return self.load_wsgiapp()
2013-10-14T02:33:15.360482+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
2013-10-14T02:33:15.360482+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
2013-10-14T02:33:15.360658+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
2013-10-14T02:33:15.360658+00:00 app[web.1]:     return util.import_app(self.app_uri)
2013-10-14T02:33:15.360658+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
2013-10-14T02:33:15.360658+00:00 app[web.1]: ImportError: No module named xxxxx

2013-10-14T02:33:15.360658+00:00 app[web.1]:     __import__(module)
2013-10-14T02:33:15.360658+00:00 app[web.1]: Traceback (most recent call last):
2013-10-14T02:33:15.360658+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
2013-10-14T02:33:15.360658+00:00 app[web.1]:     worker.init_process()
2013-10-14T02:33:15.360658+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
2013-10-14T02:33:15.360658+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2013-10-14T02:33:15.360814+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
2013-10-14T02:33:15.360814+00:00 app[web.1]:     self.callable = self.load()
2013-10-14T02:33:15.360814+00:00 app[web.1]:     return util.import_app(self.app_uri)
2013-10-14T02:33:15.360814+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
2013-10-14T02:33:15.360814+00:00 app[web.1]:     return self.load_wsgiapp()
2013-10-14T02:33:15.360814+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
2013-10-14T02:33:15.360814+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
2013-10-14T02:33:15.360814+00:00 app[web.1]:     __import__(module)
2013-10-14T02:33:15.360814+00:00 app[web.1]: ImportError: No module named xxxxx

2013-10-14T02:33:15.360814+00:00 app[web.1]: 2013-10-14 02:33:15 [7] [INFO] Worker exiting (pid: 7)
2013-10-14T02:33:15.506842+00:00 app[web.1]: 2013-10-14 02:33:15 [2] [INFO] Shutting down: Master
2013-10-14T02:33:15.506842+00:00 app[web.1]: 2013-10-14 02:33:15 [2] [INFO] Reason: Worker failed to boot.
2013-10-14T02:33:16.807631+00:00 heroku[web.1]: Process exited with status 3
2013-10-14T02:33:16.808898+00:00 heroku[web.1]: State changed from starting to crashed
2013-10-14T02:33:16.810378+00:00 heroku[web.1]: State changed from crashed to starting
2013-10-14T02:33:20.292603+00:00 heroku[web.1]: Starting process with command `gunicorn xxxxx:app`
2013-10-14T02:33:21.415595+00:00 app[web.1]: 2013-10-14 02:33:21 [2] [INFO] Starting gunicorn 18.0
2013-10-14T02:33:21.424049+00:00 app[web.1]: 2013-10-14 02:33:21 [2] [INFO] Listening at: http://0.0.0.0:21832 (2)
2013-10-14T02:33:21.424357+00:00 app[web.1]: 2013-10-14 02:33:21 [2] [INFO] Using worker: sync
2013-10-14T02:33:21.451415+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
2013-10-14T02:33:21.451415+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
2013-10-14T02:33:21.446578+00:00 app[web.1]: 2013-10-14 02:33:21 [7] [INFO] Booting worker with pid: 7
2013-10-14T02:33:21.451415+00:00 app[web.1]: 2013-10-14 02:33:21 [7] [ERROR] Exception in worker process:
2013-10-14T02:33:21.451415+00:00 app[web.1]: Traceback (most recent call last):
2013-10-14T02:33:21.451415+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
2013-10-14T02:33:21.451415+00:00 app[web.1]:     return self.load_wsgiapp()
2013-10-14T02:33:21.451582+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
2013-10-14T02:33:21.451582+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
2013-10-14T02:33:21.451415+00:00 app[web.1]:     self.callable = self.load()
2013-10-14T02:33:21.451415+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
2013-10-14T02:33:21.451582+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
2013-10-14T02:33:21.451582+00:00 app[web.1]:     worker.init_process()
2013-10-14T02:33:21.451582+00:00 app[web.1]:     return util.import_app(self.app_uri)
2013-10-14T02:33:21.451582+00:00 app[web.1]:     __import__(module)
2013-10-14T02:33:21.451415+00:00 app[web.1]:     worker.init_process()
2013-10-14T02:33:21.451765+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
2013-10-14T02:33:21.451765+00:00 app[web.1]:     return util.import_app(self.app_uri)
2013-10-14T02:33:21.451765+00:00 app[web.1]: 2013-10-14 02:33:21 [7] [INFO] Work
er exiting (pid: 7)
2013-10-14T02:33:21.451582+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
2013-10-14T02:33:21.451582+00:00 app[web.1]: Traceback (most recent call last):
2013-10-14T02:33:21.451765+00:00 app[web.1]:     self.callable = self.load()
2013-10-14T02:33:21.451765+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
2013-10-14T02:33:21.451765+00:00 app[web.1]:     return self.load_wsgiapp()
2013-10-14T02:33:21.451415+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2013-10-14T02:33:21.451765+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
2013-10-14T02:33:21.451582+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2013-10-14T02:33:21.451765+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
2013-10-14T02:33:21.451765+00:00 app[web.1]:     __import__(module)
2013-10-14T02:33:21.451582+00:00 app[web.1]: ImportError: No module named xxxxx
2013-10-14T02:33:21.451765+00:00 app[web.1]: ImportError: No module named xxxxx

2013-10-14T02:33:21.614863+00:00 app[web.1]: 2013-10-14 02:33:21 [2] [INFO] Shutting down: Master
2013-10-14T02:33:21.614999+00:00 app[web.1]: 2013-10-14 02:33:21 [2] [INFO] Reason: Worker failed to boot.
2013-10-14T02:33:22.891685+00:00 heroku[web.1]: State changed from starting to crashed
2013-10-14T02:33:22.880946+00:00 heroku[web.1]: Process exited with status 3
2013-10-14T02:33:56.309306+00:00 heroku[api]: Scale to web=1 by EMAIL@email.com
2013-10-14T02:34:38.709036+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:35:26.497306+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:35:29.339881+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:34:35.682537+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:34:36.970547+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:35:27.860267+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:36:45.618318+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:37:13.316055+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:37:16.020891+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:37:54.849200+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=
2013-10-14T02:37:14.772425+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=xxxxx.herokuapp.com fwd="68.8.230.232" dyno= connect= service= status=503 bytes=

I'm not really sure what these all mean. But I'm assuming it has to do with the gunicorn connection? Can someone help point out the issue and how I can go about fixing this?

Note: the no ImportError: No module named xxxxx --> the xxxxx is the name of my app.. It's also what I used in the procfile (eg xxxxx:app). Is this the issue?

Edit: It's a Flask application so here is the current structure that I have

   -static
      --css
      --img
      --js
   -templates
      --index.html
      --layout.html
   -.gitignore
   -Procfile
   -requirements.txt
   -app.py

My Procfile:

web: gunicorn app:app

Edit2: This is my app.py file

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def main():
    return render_template("index.html")


@app.route('/projects')
def projects():
    ...

...

if __name__ == '__main__':
    app.run()

When you configure your Procfile to say:

web: gunicorn xxxxx:app

you are giving the command that Heroku will run. Before you turn to Heroku you should ensure that you can run this command on your development machine.

The "xxxxx" argument you pass to gunicorn is the package or module that gunicorn will import to obtain your application object. If you create your application in app.py then that should be "app" (the .py extension should not be included). The error that you get occurs because gunicorn issues a import xxxxxx and that obviously fails because you have not defined a package or module with that name.

On the other side of the colon you have to put the name of your application. For example, if you have the following code in your app.py file:

app = Flask(__name__)

then your application name is app . For this setup the Procfile should read:

web: gunicorn app:app

Then gunicorn will issue a import app (the left side app ) and then look for a symbol named app in there (the right side app ).

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM