Python – Sending custom headers in websocket handshake

pythonwebsocket

How to send custom headers in the first handshake that occurs in the WebSocket protocol?

I want to use custom header in my initial request "**X-Abc-Def : xxxxx"

WebSocket clients are Python & Android client.

Best Answer

In the python websocket-client you can indeed pass custom headers easily - there's a keyword argument header available for this; see the following example from the docs:

conn = create_connection("ws://echo.websocket.org/", header={"User-Agent": "MyProgram"})

Edit: Keyword should be header, not headers.