Reputation: 245
I have apache httpd 2.4.6 running with a working django application, but occassionally during our nightly test runs, the server returns a 500 error code and I can not figure out why. There is nothing in the apache error logs indicating a reason. I have set the LogLevel to 'info' in my apache config (and reloaded apache). I modified the 'dispatch' method of my view so that it logs the request params to a file. When a successful POST is done, it logs it just fine, but there is nothing in there for the time when a 500 is returned. I don't think it's even getting to the django app before returning the 500.
So then I modified by wsgi entry point to be this:
class MyWSGIHandler(WSGIHandler):
def __call__(self, environ, start_response):
print >>environ['wsgi.errors'], pprint.pformat(environ)
retval = super(MyWSGIHandler, self).__call__(environ, start_response)
print >>environ['wsgi.errors'], pprint.pformat(retval.__dict__)
return retval
application = MyWSGIHandler()
Again, normally, this will log everything properly to my apache error log, but when the 500 is returned, there's nothing. The only thing that makes me certain that the request is making it to the server is a line in the apache access log:
[05/Jun/2014:22:41:10 +0000] "POST / HTTP/1.1" 500 600
I don't know where to go from here.
Upvotes: 0
Views: 697
Reputation: 245
I finally determined the problem. I'm using LDAP for authentication and sometimes the ldap server would time out for a user that was not in the LDAP directory. For whatever reason, this was causing the 500 to be returned. I have that user defined in a .htdigest file and had set my AuthBasicProvider to "ldap file". After I switched that around to "file ldap", I haven't seen the problem since.
Upvotes: 0
Reputation: 58523
Django will intercept unhandled exceptions in your code itself and convert them to 500 responses and doesn't propagate the exception up to the WSGI server. Thus neither the WSGI server or your wrapper will see them if that is what is occurring.
You need to configure Django to log details of such errors. One way is to set ADMINS and mail configuration so it can email them to you. The other way is to set up the logging module properly with Django so it will redirect logged messages to stderr and into the Apache error log. Have a look through the Django documentation for more information.
Upvotes: 1