Broken pipe error in Flask server

I am using Flask for some of my internal services. If you haven't used Flask, I would absolutely recommend that you check it out.

Recently I got the following error while I was attempting to serve a page from template. In an attempt to troubleshoot the error, I wasted almost half an hour.

127.0.0.1 - - [19/Jun/2012 17:48:37] "POST /" 500 -
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 55176)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 641, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------


If you happen to receive this error, most likely cause is that the template you are attempting to render using "render_template" function is not found under PROJ_ROOT/templates directory. All the templates should be present under the PROJ_ROOT/templates directory. Unfortunately you don't see an accurate error message indicating that the template is missing!

Comments

PyGuy said…
I ran into this today and it looks like it's just the browser closing the connection before the request has finished server side. I tested by creating a flask view that returned "hi" and it was still possible to get these errors depending on how I hit the flask-server from my webserver. I hope this information helps!
Dinesh said…
Thanks for the post. That's what exactly happened to me.
Anonymous said…
What about this error:

Traceback (most recent call last):
File "/home/sheshank/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 270, in run_wsgi
execute(self.server.app)
File "/home/sheshank/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 261, in execute
write(data)
File "/home/sheshank/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 227, in write
self.send_header(key, value)
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

Popular posts from this blog

Gotchas with DBCP

A note on Java's Calendar set() method

The mysterious ORA-03111 error