New submission from Jonathan Ballet <>:

While using the 'threads' middleware of repoze.debug, I noticed that sometimes,
I got the following message if I access "/debug_threads":

    URL: http://localhost:8080/debug_threads
    File '.../eggs/Paste-1.7.2-py2.5.egg/paste/evalexception/',
line 306 in respond
      app_iter = self.application(environ, detect_start_response)
    File '.../eggs/repoze.who-1.0.15-py2.5.egg/repoze/who/', line
107 in __call__
      app_iter = app(environ, wrapper.wrap_start_response)
'.../eggs/sact.utils-0.17.0dev_r201008091621-py2.5.egg/sact/utils/', line
29 in _app
      ans = app(environ, start_response)
    File '/home/jon/projects/repoze/repoze.debug/repoze/debug/', line
74 in __call__
      response.body = dump_threads()
    File '.../eggs/WebOb-', line 1719 in
      "You cannot set Response.body to a unicode object (use
    TypeError: You cannot set Response.body to a unicode object (use

And WebOb is right, since the content of dump_threads() is of type unicode (I
don't know why, because it doesn't seem to contain any unicode values, but the
pages I was requesting contained Japonese characters).

Anyway, I provide a patch which assign the content of the threads data to the
right Response attribute, depending if it's unicode or not.

files: fix-crash-on-unicode.patch
messages: 445
nosy: multani
priority: bug
status: unread
title: [repoze.debug] Don't crash if unicode presents while dumping thread 
topic: repoze.debug

Repoze Bugs <>
# HG changeset patch
# Parent 1ce4d44d669ccb0d588a39685a0850436776bd35
Don't crash if unicode values are present in threads' state.

diff -r 1ce4d44d669c repoze/debug/
--- a/repoze/debug/	Mon Aug 30 15:27:00 2010 +0200
+++ b/repoze/debug/	Mon Aug 30 16:07:05 2010 +0200
@@ -71,7 +71,11 @@
         if request.path == '/debug_threads':
             response = webob.Response(request=request)
             response.content_type = 'text/plain'
-            response.body = dump_threads()
+            t = dump_threads()
+            if isinstance(t, unicode):
+                response.unicode_body = t
+            else:
+                response.body = t
             response = request.get_response(, catch_exc_info=True)
Repoze-dev mailing list

Reply via email to