aaaa
This commit is contained in:
@@ -1,23 +1,40 @@
|
||||
def check_status(status_code: float, body: str):
|
||||
import json
|
||||
def parse_response(status_code: float, body: str):
|
||||
'''
|
||||
检查状态码和约定的返回值
|
||||
并且返回正确的body
|
||||
'''
|
||||
if status_code != 200:
|
||||
raise Exception(f"注册任务失败,状态码:{status_code}")
|
||||
if "code" not in body or body["code"] != 1:
|
||||
|
||||
data = json.loads(body)
|
||||
|
||||
if "code" not in data or data["code"] != 1:
|
||||
raise Exception(f"注册任务失败,返回值:{body}")
|
||||
|
||||
return data["data"]
|
||||
|
||||
def main(status_code: float, body: str):
|
||||
try:
|
||||
check_status(status_code, body)
|
||||
data = parse_response(status_code, body)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
task_id = body["data"]["task_id"]
|
||||
is_new_task = body["data"]["is_new_task"]
|
||||
task_id = data["task_id"]
|
||||
is_new_task = data["is_new_task"]
|
||||
|
||||
return {
|
||||
"task_id": task_id,
|
||||
"is_new_task": is_new_task
|
||||
}
|
||||
|
||||
def test():
|
||||
import json
|
||||
with open("nodes\parse_register.json", "r") as f:
|
||||
data = json.load(f)
|
||||
status_code = data["status_code"]
|
||||
body = data["body"]
|
||||
res = main(status_code, body)
|
||||
print(res)
|
||||
|
||||
test()
|
||||
Reference in New Issue
Block a user