先替换字符串中的\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-8
LANGUAGE="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 urllib

log_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 functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/client_1
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
export LANG=en_CN.GBK
export ORACLE_BASE ORACLE_HOME ORACLE_SID LD_LIBRARY_PATH PATH
export PATH LD_LIBRARY_PATH
export NLS_LANG=American_China.ZHS16GBK

 

posted on 2015-08-26 10:55  凌度  阅读(2799)  评论(0编辑  收藏  举报