**
**
在文件头部加入,来指定文件使用的编码
#-\*-coding: utf-8-\*-
利用environ来获取request的URL路径
urlPath = environ.get("PATH_INFO");
利用本身json库的相关函数,配合CSDN大神写的方法就能解析各种JSON标准格式的代码。
def analyze_json(jsons):
key_value = ''
if isinstance(jsons, dict):
for key in jsons.keys():
key_value = jsons.get(key)
if isinstance(key_value, dict):
analyze_json(key_value)
elif isinstance(key_value, list):
for json_array in key_value:
analyze_json(json_array)
else:
print(str(key) + " = " + str(key_value))
elif isinstance(jsons, list):
for json_array in jsons:
analyze_json(json_array)
def _main_():
request_body = json.loads(request_body);
analy.analyze_json(request_body);
request_body["usr_id"] #读取对应的Json字段
将sql首先通过utf-8格式编码转成字节码,然后通过latin1解码,这样就可以适应inception处理了。
request_body["sql"].encode('utf-8').decode('latin1')
str.encode('gbk')
通过 """ str """
或者 ''' str '''
来解决
resultJson = [
{
"id": row[0],
"stage": row[1].replace("'","\""),
"errlevel": row[2],
"stagestatus": row[3].replace("'","\""),
"errormessage": row[4],
"sql": row[5],
"affected_rows": row[6],
"sequence": row[7].replace("'",""),
"backup_dbname": row[8].replace("'","\""),
"execute_time": row[9].replace("'","\""),
"SQLSHA1": row[10].replace("'","\""),
"user_id": ExeData.usr_id,
"sys_information": ExeData.sys_information,
"service_information": ExeData.service_information,
"version_information": ExeData.version_information
}
for row in result
]
return [json.dumps(response).encode("utf8")];
利用zip()方法来实现同时遍历的功能
sequence,backup_db_name in zip(BackupData.sequence_list,BackupData.backup_db_name_list):
try:
rows+=cursor.execute(sqlList[i]);
except Exception as e2:
db.rollback();
print("commit failure,please try again");
else:
db.commit();