首页 > 代码库 > UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-78: ordinal not in range(128)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-78: ordinal not in range(128)

由于数据库中存有中文字符,在用python select的时候报错:

UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 0-78: ordinal not in range(128)


Solution:

在python的开头处添加下边的三行即可解决问题:

import sys

reload(sys)
sys.setdefaultencoding(‘utf8‘)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-78: ordinal not in range(128)