本文介绍了Flask 应用程序获取“IOError: [Errno 32] Broken pipe";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我使用flask来开发网络应用.

Now I use flask to develop web app.

但是一开始还不错,运行网页一段时间后,flask后端显示如下错误:

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
" % (keyword, value))
IOError: [Errno 32] Broken pipe

我的应用运行在 5000 端口 app.run(debug=True,port=5000),

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

我使用 nginx 作为 web 服务器,并在 nginx 配置文件中设置 proxy_pass http://127.0.0.1:5000.

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

现在我真的不知道哪里错了,我使用 session['email'] = request.form['email'] 而在其他文件中我使用 email =session.get('email').

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 ?

然后我设置了app.run(debug=False,port=5000),它显示了新的错误

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

为什么?

请帮帮我,谢谢.

推荐答案

内置的 werkzeug 服务器无法处理远程端关闭连接而服务器仍在输出其内容.

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.

代替 app.run(debug=True,port=5000)

试试

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

或者如果您使用的是 nginx,请按照 这里

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

我认为这是一个 werkzeug 问题

It is rather a werkzeug issue I would argue

这篇关于Flask 应用程序获取“IOError: [Errno 32] Broken pipe";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:11