102 lines
3.5 KiB
Python
102 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
快速DMS连接测试
|
||
最简化的测试脚本,用于快速验证DMS服务连接
|
||
"""
|
||
|
||
import requests
|
||
import urllib3
|
||
import json
|
||
|
||
# 禁用SSL警告
|
||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||
|
||
def quick_test():
|
||
"""快速测试DMS连接"""
|
||
|
||
url = "https://www.dev.ideas.cnpc/api/schema/manage/schema"
|
||
|
||
print("🔧 快速DMS连接测试")
|
||
print(f"URL: {url}")
|
||
print("-" * 50)
|
||
|
||
try:
|
||
# 忽略SSL证书验证
|
||
response = requests.get(url, verify=False, timeout=30)
|
||
|
||
print(f"✅ 连接成功!")
|
||
print(f"状态码: {response.status_code}")
|
||
print(f"响应头Content-Type: {response.headers.get('Content-Type', 'N/A')}")
|
||
|
||
if response.status_code == 200:
|
||
try:
|
||
data = response.json()
|
||
print(f"✅ JSON解析成功")
|
||
|
||
# 检查DMS响应结构
|
||
if isinstance(data, dict):
|
||
print(f"响应键: {list(data.keys())}")
|
||
|
||
if 'code' in data:
|
||
print(f"业务代码: {data['code']}")
|
||
if 'message' in data:
|
||
print(f"消息: {data['message']}")
|
||
if 'data' in data and isinstance(data['data'], dict):
|
||
if 'records' in data['data']:
|
||
records = data['data']['records']
|
||
print(f"API记录数量: {len(records)}")
|
||
|
||
# 显示前3个API记录
|
||
for i, record in enumerate(records[:3]):
|
||
print(f" API {i+1}: {record.get('name', 'N/A')} (domain: {record.get('domain', 'N/A')})")
|
||
|
||
print("\n🎉 DMS API连接正常!可以使用 --ignore-ssl 参数运行主程序")
|
||
return True
|
||
|
||
except json.JSONDecodeError:
|
||
print(f"❌ JSON解析失败")
|
||
print(f"响应内容: {response.text[:200]}...")
|
||
return False
|
||
else:
|
||
print(f"❌ HTTP错误: {response.status_code}")
|
||
print(f"响应内容: {response.text[:200]}...")
|
||
return False
|
||
|
||
except requests.exceptions.SSLError as e:
|
||
print(f"❌ SSL错误: {e}")
|
||
print("💡 需要使用 --ignore-ssl 参数")
|
||
return False
|
||
|
||
except requests.exceptions.ConnectionError as e:
|
||
print(f"❌ 连接错误: {e}")
|
||
print("💡 检查网络连接和服务器地址")
|
||
return False
|
||
|
||
except requests.exceptions.Timeout:
|
||
print(f"❌ 连接超时")
|
||
print("💡 网络可能较慢或服务器无响应")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print(f"❌ 其他错误: {e}")
|
||
return False
|
||
|
||
if __name__ == "__main__":
|
||
success = quick_test()
|
||
|
||
print("\n" + "=" * 50)
|
||
if success:
|
||
print("✅ 测试通过!")
|
||
print("\n💡 运行主程序的命令:")
|
||
print("python run_api_tests.py --dms ./assets/doc/dms/domain.json --ignore-ssl --strictness-level CRITICAL")
|
||
else:
|
||
print("❌ 测试失败!")
|
||
print("\n🔧 故障排除建议:")
|
||
print("1. 检查网络连接")
|
||
print("2. 确认服务器地址正确")
|
||
print("3. 检查防火墙设置")
|
||
print("4. 尝试使用curl命令测试:")
|
||
print(" curl -k https://www.dev.ideas.cnpc/api/schema/manage/schema")
|
||
|
||
print("=" * 50)
|