修改 /usr/lib/python2.7/ 下的 site.py 文件
1
$ sudo vim /usr/lib/python2.7/site.py
将设置解码函数内默认的ascii编码改为utf-8即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18def setencoding():
"""Set the string encoding used by the Unicode implementation.The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "utf-8" # 将默认编码改成utf-8即可
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !重启服务
1
$ sudo /etc/init.d/apache2 restart