赞
踩
# 可以使用assert关键字来进行断言。当条件不成立时,会引发AssertionError异常并且程序将继续执行下去 try: # 发送POST请求并获取返回结果 response = requests.request('post', login_url, data=payload, headers=headers) status_code = response.json()['code'] # print(status_code) extract_value = { 'login_token': response.json()['data']['token']['token'], 'login_Authorization': response.json()['data']['token']['principal'] } # print(extract_value) YamlUtil().write_extract_yaml(extract_value) assert response.status_code == 300 print('status_code', status_code) except AssertionError as e: print('错误状态码', str(e)) finally: print('无论是否异常都继续执行')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。