先替换字符串中的\x22 为双引号,\x0A为回车
str2 = '{\x22name\x22:\x22hao\x22 \x0A ,\x22os\x22:\x22other\x22 }print str2.decode('string_escape')
查看oracle服务器编码设置
select * from nls_database_parameters;
查看oracle客户端编码设置
select * from nls_instance_parameters;
本机NLS_CHARACTERSET=ZHS16GBK
查看客户端环境配置,需要和服务器一样配置成ZHS16GBK
cat /etc/sysconfig/i18n
LANG="zh_CN.UTF-8"#LANG="zh_CN.GB18030"#LANG=en_US.UTF-8LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"SUPPORTED="zh_CN.GB18030:zh_CN:zh"SYSFONT="lat0-sun16"SYSFONTACM="8859-15"NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
python
import urlliblog_object = eval(log_json)ry: if log_json.index('rolename') > 0 :
try: tmp_str = str(log_object['rolename']) rolename = urllib.unquote(tmp_str).decode('utf8').encode('gb18030') rolename = rolename[0:64] #write_log("rolename utf8->gbk1:" + str(log_object['rolename'])) #write_log("rolename utf8->gbk2:" + urllib.unquote(tmp_str).decode('utf8')) #write_log("rolename utf8->gbk2:" + urllib.unquote(tmp_str).decode('utf8').encode('gb18030')) except Exception,e: write_log("rolename utf8->gbk:" + tmp_str + str(e)) rolename = ''
else: rolename = ''except Exception,e: rolename = ''
或者配置oracle用户下的环境变量
vi .bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHORACLE_BASE=/u01/app/oracleORACLE_HOME=$ORACLE_BASE/product/11.2.0/client_1LD_LIBRARY_PATH=$ORACLE_HOME/libPATH=$PATH:$ORACLE_HOME/bin:$HOME/binexport LANG=en_CN.GBKexport ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATHexport PATH LD_LIBRARY_PATHexport NLS_LANG=American_China.ZHS16GBK