Troubleshooting & Debugging

Interactive debugging

Things break, and when they do, quickly pinpointing what went wrong and why makes a huge difference. By default, Pylons uses a customized version of Ian Bicking’s EvalException middleware that also includes full Mako/Myghty Traceback information.

The Debugging Screen

The debugging screen has three tabs at the top:

Traceback Provides the raw exception trace with the interactive debugger

Extra Data Displays CGI, WSGI variables at the time of the exception, in addition to configuration information

Template Human friendly traceback for Mako or Myghty templates

Since Mako and Myghty compile their templates to Python modules, it can be difficult to accurately figure out what line of the template resulted in the error. The Template tab provides the full Mako or Myghty traceback which contains accurate line numbers for your templates, and where the error originated from. If your exception was triggered before a template was rendered, no Template information will be available in this section.

Example: Exploring the Traceback

Using the interactive debugger can also be useful to gain a deeper insight into objects present only during the web request like the session and request objects.

To trigger an error so that we can explore what’s happening just raise an exception inside an action you’re curious about. In this example, we’ll raise an error in the action that’s used to display the page you’re reading this on. Here’s what the docs controller looks like:

class DocsController(BaseController):
    def view(self, url):
        if request.path_info.endswith('docs'):
            redirect_to('/docs/')
        return render('/docs/' + url)

Since we want to explore the session and request, we’ll need to bind them first. Here’s what our action now looks like with the binding and raising an exception:

def view(self, url):
    raise "hi"
    if request.path_info.endswith('docs'):
        redirect_to('/docs/')
    return render('/docs/' + url)

Here’s what exploring the Traceback from the above example looks like (Excerpt of the relevant portion):

_images/doctraceback.png

Email Options

You can make all sorts of changes to how the debugging works. For example if you disable the debug variable in the config file Pylons will email you an error report instead of displaying it as long as you provide your email address at the top of the config file:

error_email_from = you@example.com

This is very useful for a production site. Emails are sent via SMTP so you need to specify a valid SMTP server too.

Error Handling Options

A number of error handling options can be specified in the config file. These are described in the Interactive debugging documentation but the important point to remember is that debug should always be set to false in production environments otherwise if an error occurs the visitor will be presented with the developer’s interactive traceback which they could use to execute malicious code.

Project Versions

Table Of Contents

Previous topic

Unit and functional testing

Next topic

Upgrading

This Page