Skip to content

view source error in debug view, got TypeError: You cannot set Response.body to a unicode object (use Response.unicode_body) #1

@andelf

Description

@andelf

Module formencode.validators:1941 in __init__ view

when click 'view, got 500 Internal Server Error, and got:

Exception happened during processing of request from ('127.0.0.1', 60894)
Traceback (most recent call last):
  File "e:\works\pylons\devenv\lib\site-packages\paste-1.7.5.1-py2.7.egg\paste\h
ttpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "D:\Py27\Lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "D:\Py27\Lib\SocketServer.py", line 639, in __init__
    self.handle()
  File "e:\works\pylons\devenv\lib\site-packages\paste-1.7.5.1-py2.7.egg\paste\h
ttpserver.py", line 442, in handle
    BaseHTTPRequestHandler.handle(self)
  File "D:\Py27\Lib\BaseHTTPServer.py", line 337, in handle
    self.handle_one_request()
  File "e:\works\pylons\devenv\lib\site-packages\paste-1.7.5.1-py2.7.egg\paste\h
ttpserver.py", line 437, in handle_one_request
    self.wsgi_execute()
  File "e:\works\pylons\devenv\lib\site-packages\paste-1.7.5.1-py2.7.egg\paste\h
ttpserver.py", line 287, in wsgi_execute
    self.wsgi_start_response)
  File "e:\works\pylons\devenv\lib\site-packages\paste-1.7.5.1-py2.7.egg\paste\c
ascade.py", line 130, in __call__
    return self.apps[-1](environ, start_response)
  File "e:\works\pylons\devenv\lib\site-packages\paste-1.7.5.1-py2.7.egg\paste\r
egistry.py", line 379, in __call__
    app_iter = self.application(environ, start_response)
  File "e:\works\pylons\devenv\lib\site-packages\pylons-1.0-py2.7.egg\pylons\mid
dleware.py", line 150, in __call__
    self.app, environ, catch_exc_info=True)
  File "e:\works\pylons\devenv\lib\site-packages\pylons-1.0-py2.7.egg\pylons\uti
l.py", line 48, in call_wsgi_application
    app_iter = application(environ, start_response)
  File "e:\works\pylons\devenv\lib\site-packages\weberror-0.10.3-py2.7.egg\weber
ror\evalexception.py", line 233, in __call__
    return self.debug(req)(environ, start_response)
  File "e:\works\pylons\devenv\lib\site-packages\weberror-0.10.3-py2.7.egg\weber
ror\evalexception.py", line 245, in debug
    return method(req)
  File "e:\works\pylons\devenv\lib\site-packages\weberror-0.10.3-py2.7.egg\weber
ror\evalexception.py", line 391, in source_code
    res.body = 'The module %s does not have an entry in sys.modules
' % module_name
  File "build\bdist.win32\egg\webob\response.py", line 298, in _body__set
    "You cannot set Response.body to a unicode object (use Response.unicode_body
)")
TypeError: You cannot set Response.body to a unicode object (use Response.unicod
e_body)

and in weberror\evalexception.py , I found this:

    def source_code(self, req):
        location = req.params['location']  # when use print, I find location is a unicode obj
        module_name, lineno = location.split(':', 1)
        module = sys.modules.get(module_name)
        if module is None:
            # Something weird indeed
            res = Response(content_type='text/html', charset='utf8')
            res.body = 'The module %s does not have an entry in sys.modules' % module_name
            return res
 

in python we know "foo%sfoo" % u"bar" gives a unicode obj,
so maybe we need a location = srt(req.params['location']) ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions