18
votes

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.

1
eamil and email, typos? - hjpotter92
I wouldn't use the werkzeug server in production, use gunicorn or nginx uwsgi or something. - syntonym
I spell wrong, it seems not this reason. - Master Huang
Looks like I'm having the same problem: File "/usr/lib/python2.7/BaseHTTPServer.py", line 401, in send_header self.wfile.write("%s: %s\r\n" % (keyword, value)) IOError: [Errno 32] Broken pipe. I use following requirements: Babel==2.3.4 blinker==1.4 click==6.6 Flask==0.11.1 Flask-Babel==0.11.1 Flask-Mail==0.9.1 Flask-WTF==0.12 itsdangerous==0.24 Jinja2==2.8 MarkupSafe==0.23 pytz==2016.4 speaklater==1.3 Werkzeug==0.11.10 WTForms==2.1. - user3576508

1 Answers

23
votes

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