阅读背景:

关于python2.7从数据库读取中文显示乱码的问题解决

来源:互联网 
#!/usr/bin/env python
# _*_ coding:utf-8 _*_

import MySQLdb
import sys

str = raw_input("please input error code:")

conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd='123456', db='error_code',charset='utf8')
cur = conn.cursor()

sql ="select * from error_message where code = " + "'" + str + "'"

cur.execute(sql)
data=cur.fetchall()

print "分类:"+data[0][0].encode("UTF-8"),"错误码:"+data[0][1].encode("UTF-8"),"错误描述:"+data[0][2].encode("UTF-8"),"相关业务方:"+data[0][3].encode("UTF-8")


cur.close()
conn.close()
#!/usr/bin/env python
# _*_ coding:utf-8 _*



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: