# 31920: Stream - WebSocket - Handshake Error

Log Type: APPLICATION

Log Level: ERROR

## Description

Twilio returns this error when your Media Stream endpoint responds to the WebSocket connection request with an HTTP status other than 101. In most cases, the URL in `<Stream>` did not complete a valid WebSocket upgrade.

### Possible causes

* The destination server does not support WebSocket connections.
* The WebSocket protocol is not enabled for the requested URL.
* The `<Stream>` `url` points to the wrong path for your WebSocket server, so the server returns a non-101 response instead of upgrading the connection.
* The `<Stream>` `url` includes query string parameters. `<Stream>` does not support query strings, which can cause your application to reject the request.

### Possible solutions

* Verify that your server and framework are configured to accept WebSocket connections on the destination route.
* Verify that the path in your TwiML points to the exact endpoint that handles the WebSocket upgrade.
* Use `wss` in the `<Stream>` `url`. Twilio supports only `wss` for Media Streams.
* Remove query string parameters from the `<Stream>` `url`. Use nested `<Parameter>` nouns to pass custom values instead.
* Set `statusCallback` on `<Stream>` so you can review `StreamError` details when the stream fails to start.

#### Additional resources

* [Media Streams Overview](/docs/voice/media-streams)
* [TwiML `<Stream>`](/docs/voice/twiml/stream)
* [Media Streams WebSocket Messages](/docs/voice/media-streams/websocket-messages)
