Google App Engine and jQuery Ajax raises Broken Pipe error

I have a pretty standard case when I try to send some JSON data via jQuery Ajax.

My Java Script code is as follows:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type='text/javascript' src='script.js'></script>
<script type='text/javascript'>
    $(document).ready(function() {
        $("#submit").click(function() {
            $.post('/test', {test : '123'}, function(data) { alert("callback received"); }, 'json');
        });
    });
</script>

On the App Engine side, I have the following:

class Submit(webapp.RequestHandler):
    def post(self):
        logging.info(self.request.body)
        self.response.out.write("test_response")

I get JSON data logging.info(self.request.body)perfectly, but then it throws an error as soon as I send the response. The error log I get is the following:

Exception happened during processing of request from ('192.168.2.8', 38875)
Traceback (most recent call last):
  File "/usr/lib/python2.6/SocketServer.py", line 283, in handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 309, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 322, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/hw/Siine/google_appengine/google/appengine/tools/dev_appserver.py", line 3123, in init_
    BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "/usr/lib/python2.6/SocketServer.py", line 618, in __init__
    self.finish()
  File "/usr/lib/python2.6/SocketServer.py", line 661, in finish
    self.wfile.flush()
  File "/usr/lib/python2.6/socket.py", line 297, in flush
    self._sock.sendall(buffer(data, write_offset, buffer_size))
error: [Errno 32] Broken pipe

I absolutely do not know what I am doing wrong, as it seems simple.

+3
source share
3 answers

The solution was quite simple, although it took me a while to figure this out.

In the submit button <input type="submit" id="submit" value="Submit">you cannot use type="submit".

type="button", .

- , , . .

+2

, , .preventDefault() false . , .

+4

This is because dev_appserver is single-threaded and runs in the same process on your dev machine, so it cannot process two requests at the same time.

As John pointed out, and as you already discovered, you sent two simultaneous dev_server break requests.

+2
source

Source: https://habr.com/ru/post/1789569/


All Articles