V2ex PB 用中文站名浏览全部节点 出错

V2ex PB 用中文站名浏览全部节点 出错

链接:
/planes

出错提示:
Traceback (most recent call last):
File “/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py”, line 701, in __call__
handler.get(*groups)
File “/base/data/home/apps/s~nanningla/1.355367700197372389/main.py”, line 255, in get
self.values['page_title'] = self.site.title.decode(‘utf-8′) + u’ › ‘ + self.l10n.planes.decode(‘utf-8′)
File “/base/python_runtime/python_dist/lib/python2.5/encodings/utf_8.py”, line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-3: ordinal not in range(128)

把这句 self.values['page_title'] = self.site.title.decode(‘utf-8′) + u’ › ‘ + self.l10n.planes.decode(‘utf-8′)

改为 self.values['page_title'] = u’ › ‘ + self.l10n.planes.decode(‘utf-8′)

可以显示

再改为:
self.values['page_title'] = unicode(self.site.title,’mbcs’) + u’ › ‘ + self.l10n.planes.decode(‘utf-8′)

self.values['page_title'] = unicode(self.site.title,’utf-8′) + u’ › ‘ + self.l10n.planes.decode(‘utf-8′)

出错提示:
Traceback (most recent call last):
File “/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py”, line 701, in __call__
handler.get(*groups)
File “/base/data/home/apps/s~nanningla/1.355369461473654927/main.py”, line 256, in get
self.values['page_title'] = unicode(self.site.title,’mbcs’) + u’ › ‘ + self.l10n.planes.decode(‘utf-8′)
TypeError: decoding Unicode is not supported

最后改为:

self.values['page_title'] = self.site.title + u’ › ‘ + self.l10n.planes.decode(‘utf-8′)
self.site.title 是数据库出来的数据,直接已经是UTF-8编码,不用再decode.
而planes为文件设定的字符串,所以可以decode;

此条目发表在Program, 网站分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>