CherryPy Project Download

You can obtain tracebacks in cgitb format by adding this simple Tool to your arsenal:

def err():
    """Replace the default error response with an HTML traceback from cgitb."""
    import cgitb, sys
    tb = cgitb.html(sys.exc_info())
    def set_tb():
        cherrypy.response.body = tb
        cherrypy.response.headers['Content-Length'] = None
    cherrypy.request.hooks.attach('after_error_response', set_tb)
cherrypy.tools.cgitb = cherrypy.Tool('before_error_response', err)

Enable it for any URI's in a config file:

[/]
tools.cgitb.on = True

...or for a class with _cp_config:

class Root:
    
    _cp_config = {'tools.cgitb.on': True}
        
    def default(self, *args, **kwargs):
        return "args: %s kwargs: %s" % (args, kwargs)
    default.exposed = True

Attachments

Hosted by WebFaction

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