ShopTRAINING/test/quick_api_connection_test.py
2025-07-02 11:05:23 +08:00

27 lines
795 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import urllib.request
import json
def test_api():
try:
# 测试根路径
print("Testing root path...")
with urllib.request.urlopen("http://127.0.0.1:5000/", timeout=5) as response:
print(f"Root: {response.getcode()}")
except Exception as e:
print(f"Root failed: {e}")
try:
# 测试版本端点
print("Testing /api/version...")
with urllib.request.urlopen("http://127.0.0.1:5000/api/version", timeout=5) as response:
print(f"Version: {response.getcode()}")
data = response.read().decode('utf-8')
print(f"Data: {data}")
except Exception as e:
print(f"Version failed: {e}")
if __name__ == "__main__":
test_api()