We need to write bytes not strings.

Python3 compatibility issue, we need to write bytes to buffers and pipes, not strings. This should still work in python2.6+.