Dreamhost 中的 500 个错误 运行 Passenger 下的 Django
500 Errors in Dreamhost Running Django under Passenger
还是一首悲伤的老歌,但有新的信息!
我是 运行 Django 1.8.3,Python 2.7.3 作为 Pythonbrew 安装在共享 Dreamhost 服务器上;通常,在 "python manage.py address.org:8080" 下一切正常,但当直接导航到站点时无法正常工作,给出通用的 500 内部服务器错误,并且错误日志给出 header 消息的过早结束.
但是,我将“粘贴”粘贴到那里,以实际得到从跟踪中踢回的错误。
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.
我的passenger_wsgi.py就是这样格式化的
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)
编辑:中断下方的原始答案没有完全解决问题。不过,它确实起到了临时补丁的作用,并为我指出了正确的答案。
实际的、功能齐全的 Django 1.8.3 passenger_wsgi.py 应该大致如下所示,假设 Python 的正常 virtualenv 安装冻结资产:
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()
好的,所以我找到了解决方法。按照 Joran 在评论中的提示,我查看了 settings.py 并发现了
WSGI_APPLICATION = 'staff_site.wsgi.application'
并意识到 Passenger 没有加载它。阅读 Django 1.8.3 上的文档,我看到它生成了它自己的 WSGI 兼容应用程序,并且回溯似乎无法实际获得可用的应用程序。首先我试着把
application = ErrorMiddleware(WSGI_APPLICATION, debug=True)
但是失败了,Passenger 给出了 WSGI_APPLICATION 未定义的错误。因此,我尝试了一种不同的方法。现在这是我的 passenger_wsgi.py 文件,但我的信息被删除了。我保留了粘贴代码,以绕过 Django/Passenger 关于生成有用错误的分歧。如果 Dreamhost 上的任何人遇到 Django 1.8.3 的 500 错误问题,这似乎有效:
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)
还是一首悲伤的老歌,但有新的信息!
我是 运行 Django 1.8.3,Python 2.7.3 作为 Pythonbrew 安装在共享 Dreamhost 服务器上;通常,在 "python manage.py address.org:8080" 下一切正常,但当直接导航到站点时无法正常工作,给出通用的 500 内部服务器错误,并且错误日志给出 header 消息的过早结束.
但是,我将“粘贴”粘贴到那里,以实际得到从跟踪中踢回的错误。
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.
我的passenger_wsgi.py就是这样格式化的
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)
编辑:中断下方的原始答案没有完全解决问题。不过,它确实起到了临时补丁的作用,并为我指出了正确的答案。
实际的、功能齐全的 Django 1.8.3 passenger_wsgi.py 应该大致如下所示,假设 Python 的正常 virtualenv 安装冻结资产:
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()
好的,所以我找到了解决方法。按照 Joran 在评论中的提示,我查看了 settings.py 并发现了
WSGI_APPLICATION = 'staff_site.wsgi.application'
并意识到 Passenger 没有加载它。阅读 Django 1.8.3 上的文档,我看到它生成了它自己的 WSGI 兼容应用程序,并且回溯似乎无法实际获得可用的应用程序。首先我试着把
application = ErrorMiddleware(WSGI_APPLICATION, debug=True)
但是失败了,Passenger 给出了 WSGI_APPLICATION 未定义的错误。因此,我尝试了一种不同的方法。现在这是我的 passenger_wsgi.py 文件,但我的信息被删除了。我保留了粘贴代码,以绕过 Django/Passenger 关于生成有用错误的分歧。如果 Dreamhost 上的任何人遇到 Django 1.8.3 的 500 错误问题,这似乎有效:
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)