<?xml version="1.0"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>CKAN: Ticket #1267: Random exception: cannot set the body to a unicode value</title>
    <link>http://localhost/ticket/1267</link>
    <description>&lt;p&gt;
Occasionally see this problem when producing an error page. Here's an example
&lt;/p&gt;
&lt;pre class="wiki"&gt;WebApp Error: &amp;lt;type 'exceptions.TypeError'&amp;gt;: You cannot set the body to a unicode value without a charset
URL: http://at.ckan.net/authorizationgroup/new
Module weberror.errormiddleware:162 in __call__
&amp;lt;&amp;lt;              __traceback_supplement__ = Supplement, self, environ
                   sr_checker = ResponseStartChecker(start_response)
                   app_iter = self.application(environ, sr_checker)
                   return self.make_catching_iter(app_iter, environ, sr_checker)
               except:
&amp;gt;&amp;gt;  app_iter = self.application(environ, sr_checker)
Module beaker.middleware:73 in __call__
&amp;lt;&amp;lt;                                                     self.cache_manager)
               environ[self.environ_key] = self.cache_manager
               return self.app(environ, start_response)
&amp;gt;&amp;gt;  return self.app(environ, start_response)
Module beaker.middleware:152 in __call__
&amp;lt;&amp;lt;                          headers.append(('Set-cookie', cookie))
                   return start_response(status, headers, exc_info)
               return self.wrap_app(environ, session_start_response)
           def _get_session(self):
&amp;gt;&amp;gt;  return self.wrap_app(environ, session_start_response)
Module routes.middleware:130 in __call__
&amp;lt;&amp;lt;                  environ['SCRIPT_NAME'] = environ['SCRIPT_NAME'][:-1]
               response = self.app(environ, start_response)
               # Wrapped in try as in rare cases the attribute will be gone already
&amp;gt;&amp;gt;  response = self.app(environ, start_response)
Module pylons.wsgiapp:125 in __call__
&amp;lt;&amp;lt;
               controller = self.resolve(environ, start_response)
               response = self.dispatch(controller, environ, start_response)
               if 'paste.testing_variables' in environ and hasattr(response,
&amp;gt;&amp;gt;  response = self.dispatch(controller, environ, start_response)
Module pylons.wsgiapp:324 in dispatch
&amp;lt;&amp;lt;          if log_debug:
                   log.debug("Calling controller class with WSGI interface")
               return controller(environ, start_response)
           def load_test_env(self, environ):
&amp;gt;&amp;gt;  return controller(environ, start_response)
Module ckan.lib.base:117 in __call__
&amp;lt;&amp;lt;          # available in environ['pylons.routes_dict']
               try:
                   return WSGIController.__call__(self, environ, start_response)
               finally:
                   model.Session.remove()
&amp;gt;&amp;gt;  return WSGIController.__call__(self, environ, start_response)
Module pylons.controllers.core:284 in __call__
&amp;lt;&amp;lt;              if log_debug:
                       log.debug("Calling Response object to return WSGI data")
                   return response(environ, self.start_response)
               if log_debug:
&amp;gt;&amp;gt;  return response(environ, self.start_response)
Module webob.exc:248 in __call__
&amp;lt;&amp;lt;              return []
               if not self.body and not self.empty_body:
                   return self.generate_response(environ, start_response)
               return Response.__call__(self, environ, start_response)
&amp;gt;&amp;gt;  return self.generate_response(environ, start_response)
Module webob.exc:239 in generate_response
&amp;lt;&amp;lt;              status=self.status,
                   headerlist=headerlist,
                   content_type=content_type
               )
               return resp(environ, start_response)
&amp;gt;&amp;gt;  content_type=content_type
Module webob.response:94 in __init__
&amp;lt;&amp;lt;                  if charset is None:
                           raise TypeError(
                               "You cannot set the body to a unicode value without a charset")
                       body = body.encode(charset)
                   self._body = body
&amp;gt;&amp;gt;  "You cannot set the body to a unicode value without a charset")
TypeError: You cannot set the body to a unicode value without a charset
&lt;/pre&gt;</description>
    <language>en-us</language>
    <image>
      <title>CKAN</title>
      <url>http://assets.okfn.org/p/ckan/img/ckan_logo_shortname.png</url>
      <link>http://localhost/ticket/1267</link>
    </image>
    <generator>Trac 0.12.3</generator>
    <item>
      
        <dc:creator>dread</dc:creator>

      <pubDate>Tue, 09 Aug 2011 11:25:30 GMT</pubDate>
      <title></title>
      <link>http://localhost/ticket/1267#comment:1</link>
      <guid isPermaLink="false">http://localhost/ticket/1267#comment:1</guid>
      <description>
        &lt;p&gt;
John thinks it is a problem with &lt;a class="missing wiki"&gt;WebOb?&lt;/a&gt; 1.0.6
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>dread</dc:creator>

      <pubDate>Tue, 09 Aug 2011 11:56:02 GMT</pubDate>
      <title></title>
      <link>http://localhost/ticket/1267#comment:2</link>
      <guid isPermaLink="false">http://localhost/ticket/1267#comment:2</guid>
      <description>
        &lt;p&gt;
This error has been occurring on at.ckan.net which has webob 0.9.7.1-1
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>dread</dc:creator>

      <pubDate>Tue, 09 Aug 2011 12:47:51 GMT</pubDate>
      <title>status changed; owner set</title>
      <link>http://localhost/ticket/1267#comment:3</link>
      <guid isPermaLink="false">http://localhost/ticket/1267#comment:3</guid>
      <description>
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;owner&lt;/strong&gt;
              set to &lt;em&gt;dread&lt;/em&gt;
            &lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;status&lt;/strong&gt;
                changed from &lt;em&gt;new&lt;/em&gt; to &lt;em&gt;assigned&lt;/em&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;p&gt;
Running tests with &lt;a class="missing wiki"&gt;WebOb?&lt;/a&gt; 0.9.7.1, we see the error! Am now trying to fix.
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item><item>
      
        <dc:creator>dread</dc:creator>

      <pubDate>Tue, 09 Aug 2011 13:48:44 GMT</pubDate>
      <title>status changed; resolution set</title>
      <link>http://localhost/ticket/1267#comment:4</link>
      <guid isPermaLink="false">http://localhost/ticket/1267#comment:4</guid>
      <description>
          &lt;ul&gt;
            &lt;li&gt;&lt;strong&gt;status&lt;/strong&gt;
                changed from &lt;em&gt;assigned&lt;/em&gt; to &lt;em&gt;closed&lt;/em&gt;
            &lt;/li&gt;
            &lt;li&gt;&lt;strong&gt;resolution&lt;/strong&gt;
                set to &lt;em&gt;fixed&lt;/em&gt;
            &lt;/li&gt;
          &lt;/ul&gt;
        &lt;p&gt;
Fixed in cset:db5bf5b45b4f for ckan 1.4.3.
&lt;/p&gt;
&lt;p&gt;
Later versions of webob add the charset header for unicode errors (webob/exc.py:generate_response):
&lt;/p&gt;
&lt;pre class="wiki"&gt;        extra_kw = {}
        if isinstance(body, unicode):
            extra_kw.update(charset='utf-8')
        resp = Response(body,
            status=self.status,
            headerlist=headerlist,
            content_type=content_type,
            **extra_kw
        )
&lt;/pre&gt;&lt;p&gt;
This was fixed in webob cset:25fc14d49623 which went into &lt;a class="missing wiki"&gt;WebOb?&lt;/a&gt; 1.0.
&lt;/p&gt;
&lt;p&gt;
This problem affects versions from CKAN 1.4.2 back to 1.3.1. We had been avoiding this in CKAN previously by only doing abort() with a plain string.
&lt;/p&gt;
      </description>
      <category>Ticket</category>
    </item>
 </channel>
</rss>