Data has to be explicitly decoded into a string (the file is assumed to be opened as text, e.g. sys.stdout())