{
  "id": "python/aiohttp-websocket-handshake-error",
  "signature": "aiohttp.client_exceptions.WSServerHandshakeError: Invalid websocket handshake",
  "signature_zh": "aiohttp 客户端异常：无效的 WebSocket 握手",
  "regex": "aiohttp\\.client_exceptions\\.WSServerHandshakeError:\\ Invalid\\ websocket\\ handshake",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "The server does not support WebSocket protocol or the handshake response is malformed.",
  "root_cause_type": "generic",
  "root_cause_zh": "服务器不支持 WebSocket 协议或握手响应格式错误。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a different WebSocket library without checking server compatibility",
      "why_fails": "The server itself may not support WebSocket, so changing the client library won't help.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding custom headers to the handshake request",
      "why_fails": "If the server rejects WebSocket at the protocol level, custom headers won't fix it.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Verify server WebSocket endpoint and use correct URL scheme (ws:// or wss://)",
      "success_rate": 0.9,
      "how": "async with session.ws_connect('wss://example.com/ws') as ws:\n    async for msg in ws:",
      "condition": "",
      "sources": []
    },
    {
      "action": "Fall back to HTTP long polling if WebSocket fails",
      "success_rate": 0.8,
      "how": "try:\n    async with session.ws_connect(url) as ws:\n        # use websocket\nexcept aiohttp.WSServerHandshakeError:\n    # fallback to polling",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}