문제

I am trying to switch from Gunicorn to Waitress on Heroku. In the logs, I keep getting an error from Waitress:

Error: Bad module 'cardisle'

In my procfile, I have:

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

If I remove the .wsgi extension, I get a different error:

Error: Bad object name 'application'

I have tried changint the object name to wsgifunc as well since it's in the Waitress doc, but no luck.

Any help would be appreciated. I have a wsgi.py file with the following:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cardisle.settings")
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
도움이 되었습니까?

해결책

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
    django.setup()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  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
    __import__(name)

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):

cardisle/
  cardisle/
    wsgi.py
  app1/
  app2/
  app3/

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:

projectname/
  wsgi.py
  apps/
    app1/
    app2/
    app3/

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:

cardisle:wsgi.application

Not carlisle"."wsgi":"application

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top