Use sys.stdout.buffer instead of sys.stdout