How to create a python websocket with SSL and use a cookie in it?
<p>There is a way to create the websocket with SSL argument like below. </p>

<pre><code>ws = create_connection("ws://{0}/socket{1}".format(ip_addr, cookie),
                       sslopt={"cert_reqs": ssl.CERT_NONE,
                               "check_hostname": False,
                               "ssl_version": ssl.PROTOCOL_TLSv1})
</code></pre>

<p>From an example <a href="https://github.com/liris/websocket-client/blob/master/examples/echoapp_client.py" rel="nofollow noreferrer">here</a>, one of the ways to create the websocket connection is as below. However, it is not given how do I pass the SSL arguments like done above? </p>

<p>What is the way to use 'WebSocketApp' with SSL arguments as well as pass the cookie to it? </p>

<pre><code>if __name__ == "__main__":
    websocket.enableTrace(True)
    if len(sys.argv) &lt; 2:
        host = "ws://echo.websocket.org/"
    else:
        host = sys.argv[1]
    ws = websocket.WebSocketApp(host,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever()
</code></pre>