Have you tried this out at the command line?  If you had, you'd find out that body (the return value from os.listdir) is a list.  But what you want to send back to the client is a stream of bytes, aka a string, not a list.  So you have to turn this list into a string, first.