L
L
LordBH2016-02-14 20:21:11
Python
LordBH, 2016-02-14 20:21:11

Websockets return OSError raw readinto() returned invalid length?

Hello, when using web sockets on Flask, I get the same error if I reload the page in the browser two or more times. This does not prevent the server from continuing to work. But over time, he stops responding.

main.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Chat</title>
    <script type="text/javascript" src="{{ url_for('static', filename='jquery-2.2.0.js') }}"></script>
    <script type="text/javascript" src="{{ url_for('static', filename='socket.io.min.js') }}"></script>
</head>
<body>

<script type="text/javascript" charset="utf-8">

     $(document).ready(function() {

         var socket = io.connect('http://' + document.domain + ':' + location.port);

         socket.emit('connect', {data: 'U connected'});

         socket.on('apply', function (e) {
            console.log('it works');
                $('#log').append('<br>' + e.data + '<br>')

        });

     });

</script>

<h1 id="log"></h1>
</body>
</html>

app.py

from flask_socketio import SocketIO, emit
from flask import Flask, render_template


app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socket_io = SocketIO(app)


@app.route('/')
def index():
    return render_template('main.html')


@socket_io.on('connect')
def connect():
    emit('apply', {'data': "Connect"})

if __name__ == '__main__':
    socket_io.run(app, debug=True)

Error code

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/eventlet/greenpool.py", line 82, in _spawn_n_impl
    func(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/eventlet/wsgi.py", line 703, in process_request
    proto.__init__(sock, address, self)
  File "/usr/local/lib/python3.5/socketserver.py", line 684, in __init__
    self.handle()
  File "/usr/local/lib/python3.5/http/server.py", line 417, in handle
    self.handle_one_request()
  File "/usr/local/lib/python3.5/site-packages/eventlet/wsgi.py", line 315, in handle_one_request
    self.raw_requestline = self.rfile.readline(self.server.url_length_limit)
OSError: raw readinto() returned invalid length -1 (should have been between 0 and 8192)

What is the essence of this error and how to fix it?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question