quick_verify_cors.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. """
  3. 快速验证CORS配置脚本
  4. """
  5. import requests
  6. from datetime import datetime
  7. def quick_verify():
  8. """快速验证CORS配置"""
  9. print("=== CORS配置快速验证 ===")
  10. print(f"时间: {datetime.now()}")
  11. print("=" * 40)
  12. # 测试不同的Origin
  13. test_origins = [
  14. "http://localhost:5173",
  15. "http://192.168.3.218:5173"
  16. ]
  17. base_url = "http://company.citupro.com:5500"
  18. endpoint = "/api/data_parse/get-calendar-info"
  19. for origin in test_origins:
  20. print(f"\n测试Origin: {origin}")
  21. print("-" * 30)
  22. try:
  23. # 测试OPTIONS请求
  24. headers = {
  25. 'Origin': origin,
  26. 'Access-Control-Request-Method': 'GET'
  27. }
  28. response = requests.options(f"{base_url}{endpoint}", headers=headers)
  29. print(f"OPTIONS状态码: {response.status_code}")
  30. # 检查CORS头部
  31. cors_origin = response.headers.get('Access-Control-Allow-Origin', '未设置')
  32. print(f"Access-Control-Allow-Origin: {cors_origin}")
  33. if cors_origin == origin:
  34. print("✅ CORS配置正确")
  35. else:
  36. print("❌ CORS配置有问题")
  37. except Exception as e:
  38. print(f"❌ 测试失败: {e}")
  39. print("\n" + "=" * 40)
  40. print("验证完成!")
  41. print("\n如果看到✅,说明CORS配置正确。")
  42. print("如果看到❌,请重启Flask应用。")
  43. if __name__ == "__main__":
  44. quick_verify()