Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

web.debugerror doesn't display utf-8 #26

Closed
w0rm opened this Issue · 5 comments

3 participants

@w0rm

Cannot get error display correctly, check this test case

# coding: utf-8
import web
urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:        
    def GET(self, name):
        a = u"ошибка" # if remove this line and coding declaration—then everything is fine
        raise Exception("test")
if __name__ == "__main__":
    app.run()

Most of the time i get this in the browser instead of pretty djangoerror:

Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/web/wsgiserver/__init__.py", line 1174, in communicate
    req.respond()
  File "/Library/Python/2.6/site-packages/web/wsgiserver/__init__.py", line 544, in respond
    self._respond()
  File "/Library/Python/2.6/site-packages/web/wsgiserver/__init__.py", line 558, in _respond
    for chunk in response:
  File "/Library/Python/2.6/site-packages/web/utils.py", line 353, in safestr
    return str(obj)
  File "/Library/Python/2.6/site-packages/web/template.py", line 1260, in __str__
    return self["__body__"].encode('utf-8')
  File "/Library/Python/2.6/site-packages/web/template.py", line 1253, in __getitem__
    self["__body__"] = u"".join(self._data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 19: ordinal not in range(128)
@chuangbo

I fix this ugly

             # create template to make sure it compiles
             t = Template(open(path).read(), path)
@@ -1252,7 +1250,7 @@ class TemplateResult(storage, DictMixin):

     def __getitem__(self, name):
         if name == "__body__" and storage.__getitem__(self, '__body__') is None:
-            self["__body__"] = u"".join(map(safeunicode, self._data))
+            self["__body__"] = u"".join(self._data)
         return storage.__getitem__(self, name)

     def __unicode__(self): 
@w0rm

Thanks, using safeunicode helped me.

@chuangbo

This just works. But far away exactly. I don't know how the template work.

@w0rm

Unicode inconsistency in webpy troubles me a lot, every time it puts me in a doubt either I should use u"" prefix or not. webpy#27 is from the same opera.

@anandology
Collaborator

Fixed unicode error in generating debugerror (closed by fdda96d).

The web.net.websafe function works on strings, not on unicode. I wrote a
unicode version of that in template.py. Using that as filter for debugerror
template fixed the problem.

@anandology anandology referenced this issue from a commit in anandology/webpy
@anandology anandology Fixed unicode error in generating debugerror (closes #26).
The web.net.websafe function works on strings, not on unicode. I wrote a
unicode version of that in template.py. Using that as filter for debugerror
template fixed the problem.
fdda96d
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.