无解:python乱码问题


问题描述:
1、A和B都是linux服务器上边都有python程序(一样的),都安装了pymssql、freetds
2、C是xp服务器上边运行sql2005

3、A、B两个服务器都通过如下命令执行:
>>> import pymssql
>>> connection = pymssql.connect(host="192.168.0.11",user="cc",password="cc",database="cc")
>>> cursor = connection.cursor()
>>> name='时间'
>>> age='23'
>>> sql ='''insert into testdb1(name,age) values('%s','%s')'''%(name,age)
>>> cursor.execute(sql)
>>> connection.commit()

问题:
  在A服务器上运行插入的数据是正常的
  但是,在B服务器运行插入的数据是乱码

问题补充:如下设置AB都一样:
[root@localhost lsg]# locale
LANG=zh_CN.GBK
LC_CTYPE=zh_CN.UTF-8
LC_NUMERIC="zh_CN.GBK"
LC_TIME=zh_CN.UTF-8
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=
[root@localhost lsg]# echo #lang

[root@localhost lsg]# echo #languge

i18n都追加:
LANG="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_CTYPE="zh_CN.UTF-8"

profile文件追加:
LC_ALL="zh_CN.GBK"
export LANG="zh_CN.GBK"

作者“namelujl”
 

相关内容

    暂无相关文章

评论关闭