webpy之UnicodeDecodeError(又是Locale惹的祸)

对于Clubuptime无语了,肯定是这台母鸡又被国人占领了,模板的Locale居然被设置成了GBK。。。。。。

导致python部署webpy时候出现如下诡异的错误:

if sys.getdefaultencoding() != 'utf-8':

<type 'exceptions.UnicodeDecodeError'> at /

'ascii' codec can't decode byte 0xe4 in position 44: ordinal not in range(128)

Python /usr/local/lib/python2.6/dist-packages/web/template.py in read_indented_block, line 406

Web GET http://www.wikipk.net:8080/

搜了半天没搞定,最后点开本地变量,原来是在处理html(utf-8,含中文)时候的故障。

添加如下代码解决:

if sys.getdefaultencoding() != 'utf-8':
    reload(sys)
    sys.setdefaultencoding('utf-8')

2 thoughts on “webpy之UnicodeDecodeError(又是Locale惹的祸)

Leave a Reply

Your email address will not be published. Required fields are marked *