10

I'm trying to run my django application on heroku.

Folder structure:

app/
  Procfile
  docs/
  ...
  project/
    manage.py
    wsgi.py
    <django apps>

Procfile

web: gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-

Error I'm getting:

2015-02-16T16:05:00.646316+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-`
2015-02-16T16:05:02.697633+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Listening at: http://0.0.0.0:44846 (3)
2015-02-16T16:05:02.709567+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [9] [INFO] Booting worker with pid: 9
2015-02-16T16:05:02.696968+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Starting gunicorn 19.1.1
2015-02-16T16:05:02.697790+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Using worker: sync
2015-02-16T16:05:02.793753+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [10] [INFO] Booting worker with pid: 10
2015-02-16T16:05:03.157305+00:00 app[web.1]: Traceback (most recent call last):
2015-02-16T16:05:03.157311+00:00 app[web.1]:   File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-02-16T16:05:03.157351+00:00 app[web.1]:     sys.exit(run())
2015-02-16T16:05:03.157383+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-02-16T16:05:03.157461+00:00 app[web.1]:     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-02-16T16:05:03.157463+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
2015-02-16T16:05:03.157506+00:00 app[web.1]:     super(Application, self).run()
2015-02-16T16:05:03.157527+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
2015-02-16T16:05:03.157604+00:00 app[web.1]:     Arbiter(self).run()
2015-02-16T16:05:03.157607+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 196, in run
2015-02-16T16:05:03.157635+00:00 app[web.1]:     self.halt(reason=inst.reason, exit_status=inst.exit_status)
2015-02-16T16:05:03.157656+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 292, in halt
2015-02-16T16:05:03.157730+00:00 app[web.1]:     self.stop()
2015-02-16T16:05:03.157744+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 343, in stop
2015-02-16T16:05:03.157814+00:00 app[web.1]:     time.sleep(0.1)
2015-02-16T16:05:03.157836+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
2015-02-16T16:05:03.157887+00:00 app[web.1]:     self.reap_workers()
2015-02-16T16:05:03.157908+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-02-16T16:05:03.158009+00:00 app[web.1]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-02-16T16:05:03.158075+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-02-16T16:05:03.904714+00:00 heroku[web.1]: Process exited with status 1
2015-02-16T16:05:03.914410+00:00 heroku[web.1]: State changed from starting to crashed

Update 1 My wsgi.py file

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config")
os.environ.setdefault("DJANGO_CONFIGURATION", "Production")

from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()

Here I am just adding some text because SO has this silly minimum amount of text that must be written in a question. I mean, I do get it that quality needs to be kept, but if the problem is self explanatory why force people to write unneeded text? Thanks and have a great day!

Avi Meir
  • 980
  • 3
  • 11
  • 26
  • How did your WSGI file get there, rather than inside project/project which is where Django puts it? And you should show the content of that file. – Daniel Roseman Feb 16 '15 at 16:33
  • I moved wsgi.py to the project main folder, do you think that this is the issue? – Avi Meir Feb 16 '15 at 16:54
  • There's too much we don't know here. What is "config" as your DJANGO_SETTINGS_MODULE? Have you really called your settings file config.py rather than settings.py? And is it in the same directory as wsgi.py? – Daniel Roseman Feb 16 '15 at 17:13
  • I'm using pydanny's cookiecutter project template as in here: https://github.com/pydanny/cookiecutter-django the settings.py file(s) are in their own folder called config and are names common.py for the base settings and then local.py or production.py are used in locale or production environments – Avi Meir Feb 16 '15 at 17:29

5 Answers5

5

Adding --preload to the gunicorn command in the Procfile will make your Traceback a lot more readable and show you the actual errors.

Exmaple:

gunicorn project.wsgi:application --preload --workers 1
Jacob Valenta
  • 6,659
  • 8
  • 31
  • 42
3

I had a similar problem, after reading he docs for gunicorn, I was able to add

--log-level debug

to the

web: gunicorn project.wsgi:application --log-file -

such that its

web: gunicorn project.wsgi:application --log-file - --log-level debug

In my case the path was also an issue.

Philip
  • 71
  • 5
2

Finally found the solution, it was a missing dependency of django-organizations. I find it crazy that there is no way (at least not that I could find) to see any useful error output from heroku. I finally did

heroku run bash --app <app_name>

and then ran the wsgi.py file line by line, finally getting some meaningful error on

from configurations.wsgi import get_wsgi_application  # noqa

It was then clear that it's a missing module error, installed it and everything runs perfectly fine.

Avi Meir
  • 980
  • 3
  • 11
  • 26
  • Thanks you so much! I was using flask and I forgot to put one of the requirements in the requirements.txt file. Dunno why it gave this cryptic error message instead of the usual "module not found" – KetZoomer Jun 06 '21 at 02:24
1

Change your Procfile to:

web: gunicorn project.wsgi:application --log-file=-

You're missing the project module in the python path to the wsgi.py file.

schillingt
  • 13,493
  • 2
  • 32
  • 34
  • I Did it, it wasn't finding my config file so changed the line to: gunicorn project.wsgi:application --pythonpath="$PWD/project" --log-file - Still getting gunicorn.errors.HaltServer: – Avi Meir Feb 16 '15 at 16:39
  • Why are you specifying the ```pythonpath```. It doesn't look like the it's required in Heroku's docs. – schillingt Feb 16 '15 at 21:20
0

I solved it. I followed these steps: Remove all the unused libraries. Delete requirements.txt file. Create a new requirements.txt file. Commit to Git and then deploy on Heroku.