Ticket #1267 (closed defect: fixed)
Random exception: cannot set the body to a unicode value
| Reported by: | dread | Owned by: | dread |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | ckan | Keywords: | |
| Cc: | Repository: | ckan | |
| Theme: | none |
Description
Occasionally see this problem when producing an error page. Here's an example
WebApp Error: <type 'exceptions.TypeError'>: 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__
<< __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:
>> app_iter = self.application(environ, sr_checker)
Module beaker.middleware:73 in __call__
<< self.cache_manager)
environ[self.environ_key] = self.cache_manager
return self.app(environ, start_response)
>> return self.app(environ, start_response)
Module beaker.middleware:152 in __call__
<< headers.append(('Set-cookie', cookie))
return start_response(status, headers, exc_info)
return self.wrap_app(environ, session_start_response)
def _get_session(self):
>> return self.wrap_app(environ, session_start_response)
Module routes.middleware:130 in __call__
<< 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
>> response = self.app(environ, start_response)
Module pylons.wsgiapp:125 in __call__
<<
controller = self.resolve(environ, start_response)
response = self.dispatch(controller, environ, start_response)
if 'paste.testing_variables' in environ and hasattr(response,
>> response = self.dispatch(controller, environ, start_response)
Module pylons.wsgiapp:324 in dispatch
<< if log_debug:
log.debug("Calling controller class with WSGI interface")
return controller(environ, start_response)
def load_test_env(self, environ):
>> return controller(environ, start_response)
Module ckan.lib.base:117 in __call__
<< # available in environ['pylons.routes_dict']
try:
return WSGIController.__call__(self, environ, start_response)
finally:
model.Session.remove()
>> return WSGIController.__call__(self, environ, start_response)
Module pylons.controllers.core:284 in __call__
<< if log_debug:
log.debug("Calling Response object to return WSGI data")
return response(environ, self.start_response)
if log_debug:
>> return response(environ, self.start_response)
Module webob.exc:248 in __call__
<< return []
if not self.body and not self.empty_body:
return self.generate_response(environ, start_response)
return Response.__call__(self, environ, start_response)
>> return self.generate_response(environ, start_response)
Module webob.exc:239 in generate_response
<< status=self.status,
headerlist=headerlist,
content_type=content_type
)
return resp(environ, start_response)
>> content_type=content_type
Module webob.response:94 in __init__
<< 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
>> "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
Change History
comment:2 Changed 3 years ago by dread
This error has been occurring on at.ckan.net which has webob 0.9.7.1-1
comment:3 Changed 3 years ago by dread
- Owner set to dread
- Status changed from new to assigned
Running tests with WebOb? 0.9.7.1, we see the error! Am now trying to fix.
comment:4 Changed 3 years ago by dread
- Status changed from assigned to closed
- Resolution set to fixed
Fixed in cset:db5bf5b45b4f for ckan 1.4.3.
Later versions of webob add the charset header for unicode errors (webob/exc.py:generate_response):
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
)
This was fixed in webob cset:25fc14d49623 which went into WebOb? 1.0.
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.
Note: See
TracTickets for help on using
tickets.

John thinks it is a problem with WebOb? 1.0.6