2
votes

It's the same old sad song, with new info!

I'm running Django 1.8.3 with Python 2.7.3 as a Pythonbrew install on a shared Dreamhost server; as is common, everything works fine with "python manage.py address.org:8080", but isn't working when the site is navigated to directly, giving a generic 500 Internal Server Error, and the error logs give a premature end of header message.

However, I stuck Paste in there to actually get the errors being kicked back from the trace.

URL: http://staff.gchrl.org/ File '/home/syslib/staff.gchrl.org/staff_site/paste/exceptions/errormiddleware.py', line 142 in call app_iter = self.application(environ, sr_checker)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/core/handlers/wsgi.py', line 189 in call response = self.get_response(request)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/core/handlers/base.py', line 218 in get_response response = self.handle_uncaught_exception(request, resolver, sys.exc_info())

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/core/handlers/base.py', line 261 in handle_uncaught_exception return debug.technical_500_response(request, *exc_info)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/views/debug.py', line 97 in technical_500_response html = reporter.get_traceback_html()

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/views/debug.py', line 384 in get_traceback_html return t.render(c)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/base.py', line 209 in render return self._render(context)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/base.py', line 201 in _render return self.nodelist.render(context)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/base.py', line 903 in render bit = self.render_node(node, context)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/debug.py', line 79 in render_node return node.render(context)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/debug.py', line 89 in render output = self.filter_expression.resolve(context)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/base.py', line 674 in resolve new_obj = func(obj, *arg_vals)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/template/defaultfilters.py', line 779 in date return format(value, arg)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/dateformat.py', line 345 in format return df.format(format_string)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/dateformat.py', line 37 in format pieces.append(force_text(getattr(self, piece)()))

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/dateformat.py', line 270 in r return self.format('D, j M Y H:i:s O')

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/dateformat.py', line 37 in format pieces.append(force_text(getattr(self, piece)()))

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/encoding.py', line 92 in force_text s = six.text_type(s)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/functional.py', line 141 in __text_cast return func(*self.__args, **self.__kw)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/translation/init.py', line 84 in ugettext return _trans.ugettext(message)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/translation/trans_real.py', line 327 in ugettext return do_translate(message, 'ugettext')

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/translation/trans_real.py', line 304 in do_translate _default = _default or translation(settings.LANGUAGE_CODE)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/translation/trans_real.py', line 206 in translation _translations[language] = DjangoTranslation(language)

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/translation/trans_real.py', line 116 in init self._add_installed_apps_translations()

File '/home/syslib/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/site-packages/django/utils/translation/trans_real.py', line 164 in _add_installed_apps_translations

"The translation infrastructure cannot be initialized before the " AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

My passenger_wsgi.py is formatted thusly

import sys, os
INTERP = "/home/syslib/.pythonbrew/pythons/Python-2.7.3/bin/python"
#INTERP is present twice so that the new python interpreter knows the actual executable path
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
sys.path.insert(0, os.getcwd(), "staff_site")
os.environ['DJANGO_SETTINGS_MODULE'] = "staff_site.settings"
from paste.exceptions.errormiddleware import ErrorMiddleware
import django.core.handlers.wsgi
DjangoApp = django.core.handlers.wsgi.WSGIHandler()
application = ErrorMiddleware(DjangoApp, debug=True)
1
your wsgi usually has something like from staff_site.main import app as applicationJoran Beasley
@JoranBeasley Tried that change, and the error remains.slink

1 Answers

0
votes

EDIT: The original answer below the break didn't completely fix the problem. It did act as a temporary patch, though, and pointed me at the right answer.

The actual, fully functional, Django 1.8.3 passenger_wsgi.py should look roughly as follows, assuming a normal, virtualenv installation of Python to freeze assets:

import sys, os

INTERP = "/home/<username>/<domain>/public/env/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

sys.path.insert(0, os.getcwd()+"public/<your_app_name>/")
os.environ['DJANGO_SETTINGS_MODULE'] = "<your_app_name>.settings"

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

Okay, so I found the fix. Following Joran's hint in the comment, I looked over the settings.py and came across

WSGI_APPLICATION = 'staff_site.wsgi.application'

And realized that Passenger wasn't loading that. Reading the documentation on Django 1.8.3, I saw that it generates it's own WSGI-compatible application, and that the traceback seemed to be failing on actually obtaining a usable application. First I tried putting

application = ErrorMiddleware(WSGI_APPLICATION, debug=True)

But that failed, with Passenger giving an error that WSGI_APPLICATION was not defined. Thus, I tried a different approach. This is my passenger_wsgi.py file now, but with my information taken out. I preserved the Paste code, to bypass the Django/Passenger disagreement on generating useful errors. If anyone on Dreamhost is having the 500 error issue with Django 1.8.3, this seems to work:

import sys, os

INTERP = "/home/path/to/your/install/of/python"
#INTERP is present twice so that the new python interpreter knows the actual executable path
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)

sys.path.insert(0, os.getcwd()+"<your_app_name>")
os.environ['DJANGO_SETTINGS_MODULE'] = "<your_app_name>.settings"

from paste.exceptions.errormiddleware import ErrorMiddleware
import django.core.handlers.wsgi

from <your_app>.wsgi import application as DjangoApp

application = ErrorMiddleware(DjangoApp, debug=True)