#!/usr/bin/env python3 """ 测试Docker容器网络连接 """ import requests import json def main(): print("=== Docker网络连接测试 ===") # 测试配置,使用简单的配置来测试网络连接 test_config = { "base-url": "http://host.docker.internal:5001/", "dms": "./assets/doc/dms/domain.json", "stages-dir": "./custom_stages", "custom-test-cases-dir": "./custom_testcases", "verbose": True, "output": "./test_reports/", "format": "json", "generate-pdf": False, # 不生成PDF,加快测试 "strictness-level": "CRITICAL", "ignore-ssl": True } print(f"[信息] 测试Docker容器是否能访问宿主机5001端口...") try: response = requests.post( "http://localhost:5050/run", json=test_config, headers={"Content-Type": "application/json"}, timeout=30 ) print(f"[信息] HTTP状态码: {response.status_code}") if response.status_code == 200: print(f"[成功] 网络连接正常") result = response.json() print(f"[信息] 响应状态: {result.get('status', '未知')}") else: print(f"[失败] 网络连接异常") print(f"[错误] 响应: {response.text[:300]}...") except Exception as e: print(f"[错误] 网络测试失败: {e}") if __name__ == "__main__": main()