CherryPy Project Download

Using the Paste EvalException middleware with CherryPy

When developing you application you may want to inspect in details the exception or error traceback, Paste provides the evalexception module which comes with a set of WSGI middleware to perform advances debugging tasks. CherryPy let you use this module and benefit from its features. Below is a basi example on how to set it up.

import cherrypy
from paste import evalexception
from paste.httpexceptions import *

class Root:
    def index(self):
        raise HTTPBadRequest("you're doomed mate.")
    def hello(self):
        raise cherrypy.HTTPError, "aaaaaaaaaaaah"

if __name__ == '__main__':
    cherrypy.config.update({'global':{'request.throw_errors': True,
                                      'log.screen': True,
                                      'engine.autoreload_on': False}})
    # Create a WSGI application
    app = cherrypy.Application(Root())
    app.wsgiapp.pipeline.append(('paste_exc', evalexception.middleware.EvalException))
  1. Set the request.throw_errors to True. This will prevent CherryPy to handle the exception itself.
  2. Add the evalexception.middleware.EvalException to the application pipeline of WSGI middlewares.

Et voilĂ .

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages