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

在执行python脚本时报如下错误:

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


解决方法:

在python脚本中开头处加上以下两句代码即可:

reload(sys) 
sys.setdefaultencoding('utf8')

例如:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Autor: Joe


import sys
import time
import MySQLdb

reload(sys) 
sys.setdefaultencoding('utf8')

......


你可能感兴趣的:(python,脚本,ASCII)