77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试云端API访问
|
|
"""
|
|
import requests
|
|
import json
|
|
from datetime import datetime, timedelta
|
|
|
|
def test_cloud_api():
|
|
"""测试云端报警查询API"""
|
|
|
|
# 云端服务器地址
|
|
base_url = "http://115.190.167.176:30088"
|
|
api_url = f"{base_url}/api/device-alarms"
|
|
|
|
# 测试参数
|
|
params = {
|
|
'physicalUid': 'dev_host_2', # 测试设备UID
|
|
'limit': 10,
|
|
'since': int((datetime.now() - timedelta(hours=24)).timestamp() * 1000) # 24小时前
|
|
}
|
|
|
|
print(f"🔍 测试云端API访问")
|
|
print(f"URL: {api_url}")
|
|
print(f"参数: {params}")
|
|
print("-" * 50)
|
|
|
|
try:
|
|
# 发起GET请求
|
|
response = requests.get(api_url, params=params, timeout=10)
|
|
|
|
print(f"✅ HTTP状态码: {response.status_code}")
|
|
print(f"📋 响应头: {dict(response.headers)}")
|
|
|
|
if response.status_code == 200:
|
|
try:
|
|
data = response.json()
|
|
print(f"✅ 响应数据: {json.dumps(data, indent=2, ensure_ascii=False)}")
|
|
except json.JSONDecodeError:
|
|
print(f"⚠️ 响应不是JSON格式: {response.text}")
|
|
else:
|
|
print(f"❌ 请求失败: {response.status_code}")
|
|
print(f"错误内容: {response.text}")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ 连接失败:无法连接到服务器")
|
|
except requests.exceptions.Timeout:
|
|
print("❌ 请求超时")
|
|
except Exception as e:
|
|
print(f"❌ 请求异常: {e}")
|
|
|
|
def test_server_health():
|
|
"""测试服务器健康状态"""
|
|
base_url = "http://115.190.167.176:30088"
|
|
|
|
print(f"\n🏥 测试服务器健康状态")
|
|
print(f"服务器: {base_url}")
|
|
print("-" * 50)
|
|
|
|
# 测试根路径
|
|
try:
|
|
response = requests.get(base_url, timeout=5)
|
|
print(f"✅ 根路径访问: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ 根路径访问失败: {e}")
|
|
|
|
# 测试API路径
|
|
try:
|
|
response = requests.get(f"{base_url}/api", timeout=5)
|
|
print(f"✅ API路径访问: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ API路径访问失败: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
test_server_health()
|
|
test_cloud_api()
|