Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging "Premature end of script headers" - WSGI/Django

Tags:

django

I have recently deployed an app to a shared host (webfaction), and for no apparent reason, my site will not load at all (it worked until today).

It is a django app, but the django.log is not even created; the only clue is that in one of the logs, I get the error message: "Premature end of script headers", identifying my wsgi file as the source.

I've tried to add logging to my wsgi file, but I can't find any log created for it. Is there any recommended way to debug this error? I am on the point of tearing my hair out.

My WSGI file:

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

import logging

logger = logging.getLogger(__name__)


os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ['CELERY_LOADER'] = 'django'

virtenv = os.path.expanduser("~/webapps/django/oneclickcosvirt/")
activate_this = virtenv + "bin/activate_this.py"
execfile(activate_this, dict(__file__=activate_this))

# if 'VIRTUAL_ENV' not in os.environ:
#    os.environ['VIRTUAL_ENV'] = virtenv

sys.path.append(os.path.dirname(virtenv+'oneclickcos/'))

logger.debug('About to run WSGIHandler')

try:
        application = WSGIHandler()
except (Exception,), e:
       logger.debug('Exception starting wsgihandler: %s' % e)
       raise e
like image 225
Marcin Avatar asked Mar 26 '12 14:03

Marcin


1 Answers

It's hard to define exact reason of error without webserver log:

Probable solutions: http://code.google.com/p/modwsgi/wiki/InstallationIssues#Multiple_Python_Versions

And d http://code.google.com/p/modwsgi/wiki/FrequentlyAskedQuestions

Q: Why am I seeing the error message 'premature end of script headers' in the Apache error logs.

A: If using daemon mode, this is a symptom of the mod_wsgi daemon process crashing when handling a request. You would probably also see the message 'segmentation fault'. See answer for question about 'segmentation fault' above.

This error message can also occur where you haven't configured Apache correctly and your WSGI script file is being executed as a CGI script instead.

Hope it will help

like image 195
Pavleg Avatar answered Nov 06 '22 22:11

Pavleg