title: python Flask socketio 404/400 from browser
body: <p>I'm trying to run a flask-socketio server that connects to a react app in the browser. </p>
  
  <p>python Server code (relevant portions):</p>
  
  <pre><code>from flask import Flask, request, jsonify
  from flask_socketio import SocketIO
  
  app = Flask(__name__)
  socketio = SocketIO(app)
  
  @socketio.on('message')
  def handle_message(message):
      print('received message: ' + message)
  
  if __name__ == '__main__':
      socketio.run(app)
  </code></pre>
  
  <p>client js(running in browser):</p>
  
  <pre><code>var ws = new WebSocket("ws://127.0.0.1:5000");
  console.log('connecting to log ws')
  ws.onopen = function (event) {
    console.log('connection opened')
  };
  ws.onmessage = function (event) {
    console.log(event.data);
    self.recieve(event.data);
  }
  </code></pre>
  
  <p>I get the following error in the browser:</p>
  
  <pre><code>failed: Error during WebSocket handshake: Unexpected response code: 404
  </code></pre>
  
  <p>Now I've heard that this is often because I've made a mistake in the url I use. However, when I change </p>
  
  <p><code>var ws = new WebSocket("ws://127.0.0.1:5000");</code> </p>
  
  <p>to </p>
  
  <p><code>var ws = new WebSocket("wss://127.0.0.1:5000");</code> </p>
  
  <p>I can see that the server gets the connection request, but it returns the following error on the server side:</p>
  
  <pre><code>127.0.0.1 - - [02/Nov/2017 13:07:59] code 400, message Bad HTTP/0.9 request 
  type ('\x16\x03\x01\x00t\x01\x00\x00p\x03\x01Y\xfb{\x1f\x0
  5\x8d\xbf|\xdb\xeb\x12\xe8\xf6\xb0\xf9')
  </code></pre>
  
  <p>What do i need to do to get a successful connection set up here? The browser used here is chrome, but Im having difficulty with others as well.</p>