mod_wsgi & Django: Stack trace does not show in log files or gets sent by email

908 views
Skip to first unread message

Stefan Wallner

unread,
Dec 14, 2008, 3:56:21 PM12/14/08
to modwsgi
Hi,
let me first admit that this is a repost of my message to django-users
since I am now beginning to wonder if this is more a mod_wsgi
(configuration/etc) issue instead of Django related. Sorry for
crossposting, but this problem is given me a major headache and I
cannot seem to find anything wrong with the Django configuration.

Thanks for any help, if you need more details let me know.

Stefan




Message from django-users (http://groups.google.com/group/django-users/
browse_thread/thread/75102033de50ee06)


I am running Django 1.0 on Windows Server 2003, Python 2.5 with
mod_wsgi. I am having trouble capturing any exceptions in my code
either through Apache's error log or by having an email sent to me.
As a simple test I added
a = [1,2,3]
b = a[4]
to the top of one of my views, which does generate an IndexError
exception, but is not being reported in the error log or by email
either.
The mod_wsgi configuration is stricly as described on mod_wsgi's
website (http://code.google.com/p/modwsgi/wiki/
IntegrationWithDjango),
but even with LogLevel info in my Apache conf I do not see anything
in
my error log (related to the exception in the Django code, a bunch of
other Apache messages do get printed).
As for receiving the stack traces via email I have SERVER_EMAIL, etc.
setup and can confirm that it works when I am running it with the
development server and I can send email on this server (tested both
on
the dev server and the production server by a different part of code
in my application).
If DEBUG is set to True I can see the stack trace in the browser, but
with true production mode all errors are silently lost.
Any ideas or pointers on what is going on or what else I should do?
Thanks,
Stefan

Nimrod A. Abing

unread,
Dec 15, 2008, 1:58:44 AM12/15/08
to mod...@googlegroups.com
On Mon, Dec 15, 2008 at 4:56 AM, Stefan Wallner
<monto...@googlemail.com> wrote:
>
> Hi,
> let me first admit that this is a repost of my message to django-users
> since I am now beginning to wonder if this is more a mod_wsgi
> (configuration/etc) issue instead of Django related. Sorry for
> crossposting, but this problem is given me a major headache and I
> cannot seem to find anything wrong with the Django configuration.
>
> Thanks for any help, if you need more details let me know.

Are your development and production server configurations identical?
Maybe you are just doing some things differently on your production
server?

Do you have ADMINS set to a list of emails that will receive the error
messages? If you only have one email address in there remember to add
a trailing comma after that single email address:

ADMINS = (
('Admin Example', 'ad...@example.com'),
)

Also, traceback info will usually go into a separate log file. Not
sure how you installed and configured Apache on Windows but there
should be a "errors" file where all the Traceback info gets logged.
You might also want to check Windows system event logs.

You can also try sending email from your production server using
Django's mail sending function. Use your SERVER_EMAIL as the From
address with the email addresses you have in ADMINS as the recipients
and see what happens. Set up a simple view to do just that, so that it
executes within the context of your Apache and mod_wsgi setup.
--
Best Regards,
Nimrod A. Abing

W http://arsenic.ph/
W http://preownedcar.com/
W http://preownedbike.com/
W http://abing.gotdns.com/

Stefan Wallner

unread,
Dec 15, 2008, 4:00:29 PM12/15/08
to modwsgi
> Are your development and production server configurations identical?
> Maybe you are just doing some things differently on your production
> server?
I diffed the settings file both for local development and production
use, but nothing seems different than what is supposed to (i.e.
database settings, etc).


> Do you have ADMINS set to a list of emails that will receive the error
> messages? If you only have one email address in there remember to add
> a trailing comma after that single email address:
>
> ADMINS = (
> ('Admin Example', 'ad...@example.com'),
> )
Checked that and looks good.

> Also, traceback info will usually go into a separate log file. Not
> sure how you installed and configured Apache on Windows but there
> should be a "errors" file where all the Traceback info gets logged.
> You might also want to check Windows system event logs.
I checked the Apache main error log before, nothing. The system log
does not show anything either, but I never heard of Apache logging
anything there, anyway?w

>
> You can also try sending email from your production server using
> Django's mail sending function. Use your SERVER_EMAIL as the From
> address with the email addresses you have in ADMINS as the recipients
> and see what happens. Set up a simple view to do just that, so that it
> executes within the context of your Apache and mod_wsgi setup.
Tried it, works fine, too.

I am going slightly insane right now...

Anyone with other ideas of where to look?

Thanks
Stefan

Graham Dumpleton

unread,
Dec 15, 2008, 6:03:19 PM12/15/08
to mod...@googlegroups.com
2008/12/16 Stefan Wallner <monto...@googlemail.com>:

Sorry that haven't really responded about this, has been a hectic
couple of weeks with a 1st birthday party and me starting to take over
daddy day care duties a few days a week.

Anyway, what version of mod_wsgi are you using?

Are you using VirtualHost directive?

Do you have any CustomLog/LogLevel directives inside of the VirtualHost?

Graham

Robert Coup

unread,
Dec 15, 2008, 7:36:48 PM12/15/08
to mod...@googlegroups.com
If Django is catching the error (ie. if DEBUG=True then you get a fancy formatted error page), then its a Django problem that its not being emailed to you. mod-wsgi doesn't get involved in that process at all. The only  time you'd see an error/traceback in the apache logs should be if there's a syntax error and the Django app can't load/run at all, or if the exception occurs really high up in the Django WSGI handler (unlikely).

So maybe its a mail setting? I suspect (but haven't checked) that Django fails silently if it has problems trying to send error emails. Can your web server user send mail (console via mailx or in python as described earlier in the thread) -- "sudo su - www-data" (in Debian/Ubuntu) to become such a user.

Just some ideas,

Rob :)

Stefan Wallner

unread,
Dec 17, 2008, 3:54:57 PM12/17/08
to modwsgi
> Sorry that haven't really responded about this, has been a hectic
> couple of weeks with a 1st birthday party and me starting to take over
> daddy day care duties a few days a week.
Not a problem, family first.

>
> Anyway, what version of mod_wsgi are you using?
2.3

>
> Are you using VirtualHost directive?
No. It's an out-of-the-box Apache install only with the additions for
Django/mod_wsgi.

> Do you have any CustomLog/LogLevel directives inside of the VirtualHost?
No. I did increase the LogLevel to debug at some point but did not get
any other useful informaiton, either.


> Graham

Stefan Wallner

unread,
Dec 17, 2008, 3:57:34 PM12/17/08
to modwsgi


On Dec 16, 1:36 am, "Robert Coup" <robert.c...@koordinates.com> wrote:
> If Django is catching the error (ie. if DEBUG=True then you get a fancy
> formatted error page), then its a Django problem that its not being emailed
> to you. mod-wsgi doesn't get involved in that process at all. The only  time
> you'd see an error/traceback in the apache logs should be if there's a
> syntax error and the Django app can't load/run at all, or if the exception
> occurs really high up in the Django WSGI handler (unlikely).

Email being Django's responsibility I agree, but the IndexError
generated by

a = [1,2,3]
b = a[4]

should give me a traceback in the log file and not even that is
showing...


> So maybe its a mail setting? I suspect (but haven't checked) that Django
> fails silently if it has problems trying to send error emails. Can your web
> server user send mail (console via mailx or in python as described earlier
> in the thread) -- "sudo su - www-data" (in Debian/Ubuntu) to become such a
> user.
As stated in my original post some other part of my code does send
email succesfully, so I do not think it's a problem with permissions
etc.

Graham Dumpleton

unread,
Dec 17, 2008, 4:03:30 PM12/17/08
to mod...@googlegroups.com
2008/12/18 Stefan Wallner <monto...@googlemail.com>:

Lets make sure that mod_wsgi logging is working at all.

If you add before that code:

import sys
print >> sys.stderr, "ABOUT TO ERROR"

Does that appear in Apache error log?

Graham

Stefan Wallner

unread,
Dec 18, 2008, 2:18:55 AM12/18/08
to modwsgi
> Lets make sure that mod_wsgi logging is working at all.
>
> If you add before that code:
>
>   import sys
>   print >> sys.stderr, "ABOUT TO ERROR"
>
> Does that appear in Apache error log?
>
Duh, should have though about this before. This indeed works, so I
guess that Django catches the exception but never logs or mails it? At
least now I have a better idea of what's going on, thank you!

Nimrod A. Abing

unread,
Dec 18, 2008, 3:11:19 AM12/18/08
to mod...@googlegroups.com

We use Django (heavily patched pre-1.0) and every time our site
encounters an Internal Server Error (usually due to canceled file
uploads), it *always* gets logged in errors log along with a
traceback. We have also set it up so that tracebacks are mailed to dev
team. But this is on Linux, so either this is Windows-specific or
Django version-specific.

Reply all
Reply to author
Forward
0 new messages