Emailing tracebacks in web.py
Most web apps have bugs. It’s just the way things are — you usually need to launch before you’re satisfied your latest startup is 100% bug-free, if there is such a thing. One of the nice things about a web app is that it’s easy to let your first users help you find bugs.
Both microPledge and DecentURL use Python and the minimalist web.py framework. It’s easy to set up web.py to show nice error tracebacks to the user (good for development), but it’s not a built-in feature to email real tracebacks to the site admins.
We’ve found emailed tracebacks particularly handy, so I thought I’d share the code. Nothing fancy, but it works well, and has proved invaluable for the live debugging of our own web applications. I’m not terribly familiar with other web frameworks, but I imagine the concept wouldn’t be too hard to port.
A couple of security notes:
- If your site’s at all sensitive, it’s important to serve up tracebacks via HTTPS and to check that the user viewing the page is an “admin” user. There’s lots of sensitive info in some of these tracebacks, including source snippets, database passwords, etc.
- This is why you don’t want to email the tracebacks as attachments directly — email is sent in the clear.
Anyway, have a look at the code: emailerror.py. It’s a stand-alone web.py WSGI app that shows you how to do it. Have fun!
20 November 2007 by Ben 4 comments
4 comments (oldest first)
Excellent work! Utility Mill has got them now. Very useful indeed.
Great stuff. I have some code lying around for generating bug reports for regular Python apps. Maybe I’ll post it sometime.
Paste (and by extension Pylons) do this as WSGI middleware; the exception catcher wraps your application, and if an exception escapes from your application it is handled by the middleware. It can display it and/or email it to you. It’s also what the interactive debugger is built on.
This stuff has been extracted into a separate project recently: https://www.knowledgetap.com/hg/weberror/ — I don’t know if web.py makes this sort of middleware easy to apply to an application.
A thousand thanks Ben! Simple yet very useful! We’ll sure use it in our web.py app too :) In fact, http://xhtml-css.com currently doesn’t provide us yet with much error feedback and your solution comes really in time! Thank you!