2025-12-29 14:42:33 +08:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
def parse_response(status_code: float, body: str):
|
2025-12-23 01:55:59 +08:00
|
|
|
'''
|
|
|
|
|
检查状态码和约定的返回值
|
2025-12-29 14:42:33 +08:00
|
|
|
并且返回正确的body
|
2025-12-23 01:55:59 +08:00
|
|
|
'''
|
|
|
|
|
if status_code != 200:
|
|
|
|
|
raise Exception(f"注册任务失败,状态码:{status_code}")
|
2025-12-29 14:42:33 +08:00
|
|
|
|
|
|
|
|
data = json.loads(body)
|
|
|
|
|
|
|
|
|
|
if "code" not in data or data["code"] != 1:
|
2025-12-23 01:55:59 +08:00
|
|
|
raise Exception(f"注册任务失败,返回值:{body}")
|
2025-12-29 14:42:33 +08:00
|
|
|
|
|
|
|
|
return data["data"]
|
2025-12-23 01:55:59 +08:00
|
|
|
|
|
|
|
|
def main(status_code: float, body: str):
|
|
|
|
|
try:
|
2025-12-29 14:42:33 +08:00
|
|
|
data = parse_response(status_code, body)
|
2025-12-23 01:55:59 +08:00
|
|
|
except Exception as e:
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
2025-12-29 14:42:33 +08:00
|
|
|
"add_urls_result": data
|
2025-12-23 01:55:59 +08:00
|
|
|
}
|