UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-11: ordinal not in range(128)
解决UnicodeEncodeError: 'ascii' codec can't encode characters in position
转自:http://cooler1217.iteye.com/blog/1465335
异常: 'ascii' codec can't encode characters
字符集的问题,在文件前加两句话:
reload(sys)
sys.setdefaultencoding( "utf-8" )
完美解决,ok
另外(非转载):1. 当字符串里有 \n、\t、\r时,json.loads()失效,异常,要去掉;
2. 在操作数据库的时候用到 BasicDataSource 时,可以通过设置characterEncoding来解决中文乱码的问题,
BasicDataSource connPool;connPool.addConnectionProperty("characterEncoding", "UTF-8");;
http://blog.csdn.net/junshao90/article/details/7974030