Right, there is a socket.error ( for write ) and  EOFError for read_until, I'll edit the code.
Thanks for pointing this out