#!/usr/bin/env python3 """ 快速验证CORS配置脚本 """ import requests from datetime import datetime def quick_verify(): """快速验证CORS配置""" print("=== CORS配置快速验证 ===") print(f"时间: {datetime.now()}") print("=" * 40) # 测试不同的Origin test_origins = [ "http://localhost:5173", "http://192.168.3.218:5173" ] base_url = "http://company.citupro.com:5500" endpoint = "/api/data_parse/get-calendar-info" for origin in test_origins: print(f"\n测试Origin: {origin}") print("-" * 30) try: # 测试OPTIONS请求 headers = { 'Origin': origin, 'Access-Control-Request-Method': 'GET' } response = requests.options(f"{base_url}{endpoint}", headers=headers) print(f"OPTIONS状态码: {response.status_code}") # 检查CORS头部 cors_origin = response.headers.get('Access-Control-Allow-Origin', '未设置') print(f"Access-Control-Allow-Origin: {cors_origin}") if cors_origin == origin: print("✅ CORS配置正确") else: print("❌ CORS配置有问题") except Exception as e: print(f"❌ 测试失败: {e}") print("\n" + "=" * 40) print("验证完成!") print("\n如果看到✅,说明CORS配置正确。") print("如果看到❌,请重启Flask应用。") if __name__ == "__main__": quick_verify()