-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_find_route.py
More file actions
41 lines (35 loc) · 1.27 KB
/
test_api_find_route.py
File metadata and controls
41 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests
import json
# API URL
API_URL = 'http://localhost:5000/api/find_route'
params = {
# 出发、到达车站
'start': 'Spawn',
'end': 'Lake City',
# 寻路参数
'algorithm': 'default', # default, theory, real
'ignored_lines': [],
'avoid_stations': [],
'disable_high_speed': True,
'disable_boat': False,
'enable_wild': False,
'only_lrt': False
}
# 发送POST请求并打印原始响应
if __name__ == '__main__':
print(f"调用API: {API_URL}")
print(f"参数: {json.dumps(params, ensure_ascii=False, indent=2)}")
print("=" * 70)
try:
# 发送POST请求,不使用代理
response = requests.post(API_URL, json=params, proxies={'http': None, 'https': None})
response.raise_for_status() # 检查请求是否成功
# 打印原始JSON结果
print("原始API响应:")
print(json.dumps(response.json(), ensure_ascii=False, indent=2))
with open("webui_return.json", "w", encoding="utf-8") as file:
file.write(json.dumps(response.json(), ensure_ascii=False, indent=2))
except requests.exceptions.RequestException as e:
print(f"API调用失败: {e}")
except json.JSONDecodeError as e:
print(f"JSON解析失败: {e}")