Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask app get "IOError: [Errno 32] Broken pipe"

Now I use flask to develop web app.

But at first it works well,after operating web page for a while,the flask back-end shows error like these:

   File "/usr/lib64/python2.6/BaseHTTPServer.py", line 329, in handle
    self.handle_one_request()
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 251, in handle_one_request
    return self.run_wsgi()
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 193, in run_wsgi
    execute(self.server.app)
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 184, in execute
    write(data)
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 152, in write
    self.send_header(key, value)
  File "/usr/lib64/python2.6/BaseHTTPServer.py", line 390, in send_header
    self.wfile.write("%s: %s\r\n" % (keyword, value))
IOError: [Errno 32] Broken pipe

My app run on port 5000 app.run(debug=True,port=5000),

I use nginx as web server,and set proxy_pass http://127.0.0.1:5000 in nginx config file.

Now I really don't know where is the wrong,I use session['email'] = request.form['email'] and in other file I use email = session.get('email').

Is this usage right? How to set session active period?

or any other reason cause this error ?

then I set app.run(debug=False,port=5000),it shows new error

File "/usr/lib64/python2.6/SocketServer.py", line 671, in finish
    self.wfile.flush()
  File "/usr/lib64/python2.6/socket.py", line 303, in flush
    self._sock.sendall(buffer(data, write_offset, buffer_size))
socket.error: [Errno 32] Broken pipe

why ?

Please help me,thks.

like image 218
Master Huang Avatar asked Jun 22 '16 08:06

Master Huang


1 Answers

The built-in werkzeug server is not capable of handling the remote end closing the connection while the server is still churing its content out.

instead of app.run(debug=True,port=5000)

try

from gevent.wsgi import WSGIServer
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()

or if you are using nginx, use it with uwsgi as described here

It is rather a werkzeug issue I would argue

like image 169
user2829759 Avatar answered Sep 18 '22 18:09

user2829759