Question

How can I keep Twisted from sending traceback to the browser when it has an error? It's been exposing file paths and code.

enter image description here

Was it helpful?

Solution

Just about every server framework that serves up something human readable will have an option to serve up tracebacks (for development) or not (for production).

In Twisted, it's called displayTracebacks, and it's documented as a member of twisted.web.server.Site. You configure it the same way(s) you configure anything else in Twisted. (The corresponding one-word option, e.g., for command-line flags, is notracebacks.)

If you're wondering why it defaults to True, you may want to read Glyph's rationale on the 2003 feature request that added this flag in the first place:

Nope, this should be turned on by default, since when you are using defaults you are typically developing. System administrators can make this a site-local default by adding to sitecustomize.py or somesuch.

(As the 11-years-wiser version of Glyph points out in a comment, it's probably better to set it in the application than to use a site-local default. But the basic idea is the same. Set it to False at any level, and you'll get exactly the behavior you're after.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top