Skip to content
masterclass Buddy

FastAPI · Error

WebSocketException

WebSocketException lets a FastAPI WebSocket endpoint reject a client with a closing code and optional reason. Raise it for client errors such as invalid authentication or invalid data.

Last updated

Syntax

WebSocketException(code, reason=None)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • WebSocket
  • status
  • Depends
  • Cookie
  • Query
  • FastAPI

Source: Exceptions - HTTPException and WebSocketException. Checked 2026-11-03.