[Solved]-Waitress on Heroku giving error


Here’s an awful fact about waitress: it is hiding info from you.

If you look at the source, “Bad Module” is code for “There was a failure importing your application from the wsgi module.”

To see the error, try:

  1. logging into a dyno with heroku run bash
  2. navigating to the directory with wsgi.py in it (with cd)
  3. opening a shell with python
  4. running import wsgi

When I hit this error and did this, I got:

~/proj/proj $ python

Python 2.7.9 (default, Dec 11 2014, 17:18:51) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wsgi

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "wsgi.py", line 36, in <module>
    application = get_wsgi_application()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
  File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
  File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
    module = import_module(entry)
  File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module

ImportError: No module named debug_toolbar

Which is a much more helpful error. In my case, I had set DJANGO_SETTINGS_MODULE to ‘local’ in production, (which did not have the appropriate requirements,) and so the import failed.

The exact nature of your problem will vary, but I’ll mention a case that frustrated me when I started out:

If you are running web: waitress-serve --port=$PORT cardisle.wsgi:application, you may need to change your PYTHONPATH environment variable so that PYTHONPATH+cardisle.wsgi is a fully-formed extant path on the machine in question.

I’ll open a PR for waitress this evening that tries to bubble up the import error. Best of luck otherwise!


The wsgi.py file should be in the cardisle directory. Waitress is trying to import cardisle.wsgi.


I think I found the answer. If your project is laid out like this (as they are by default):


Try this Procfile instead:

web: waitress-serve --port=$PORT cardisle.cardisle.wsgi:application

I thought of this because Dave Hall’s sample project has a different layout:


Which has the wsgi.py file at a higher level. You probably followed his tutorial, but as far as I can tell the default Django layout doesn’t quite work like that.


Try modifying your WSGI file like this(For Django 1.7):

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I had the same error because before, my Procfile was configured as explained on the Heroku guide:

 from django.core.wsgi import get_wsgi_application
 from dj_static import Cling

 application = Cling(get_wsgi_application())

And this was causing an issue for me.



Try to use:


Not carlisle"."wsgi":"application

Leave a comment