run_main方法中添加依赖数据的方法提示key错误
来源:10-8 项目实战之数据依赖调试及组装
qq_精慕门8524681
2020-03-23
老师,请问下为何我只要将run_main方法中添加了这段代码,他就会提示我的keyError错误。下面是我的run_main方法的代码,如果不添加这段代码,就可以正常运行。。。你看下是我哪里出现了问题。
class RunMain:
def run_case(self):
rows = excel_data.get_row()
for i in range(rows):
data = excel_data.get_row_value(i+2)
is_run = data[2]
if is_run == ‘yes’:
url = data[5]
excepect_method = data[11]
excepect_result = data[12]
head = data[8]
if head == ‘yes’:
head = get_header()
method = data[6]
is_depend = data[3]
data = json.loads(data[7])
if is_depend:
is_depend_key = data[4]
depend_data = get_data(is_depend)
data[depend_data] = depend_data
res = request.run_main(method=method,url=url,data=data,header=head)
print(res)
code = res[‘state’]
message = res[‘success’]
message = str(message)
code = res[‘state’]
message = res[‘success’]
message = str(message)
if excepect_method == “mec”:
config_message = handle_result(url, “state”)
config_message1 = handle_result(url, “success”)
if code == config_message and message == config_message1:
excel_data.excel_write_data(i + 2, 14, “通过”)
else:
excel_data.excel_write_data(i + 2, 14, “失败”)
excel_data.excel_write_data(i + 2, 15, json.dumps(res))
if excepect_method == "errorcode":
if code == excepect_result:
excel_data.excel_write_data(i + 2, 14, "通过")
else:
excel_data.excel_write_data(i + 2, 14, "失败")
excel_data.excel_write_data(i + 2, 15, json.dumps(res))
if excepect_method == "json":
if code == "1":
get_result = get_result_json(url, "data")
reslut = handle_result_json(res["data"], get_result)
if reslut == True:
excel_data.excel_write_data(i + 2, 14, "通过")
else:
excel_data.excel_write_data(i + 2, 14, "失败")
excel_data.excel_write_data(i + 2, 15, json.dumps(res))
if name == ‘main’:
run = RunMain()
print(run.run_case())
2回答
-
Mushishi
2020-03-31
你去把你data打印出来,看一下有没有data里面 key=4的
00 -
Mushishi
2020-03-26
你得key就是一个数字4?不报错?
012020-03-30
相似问题