import sys from wsgiref.handlers import CGIHandler sys.stdout = sys.stdout.buffer # set stdout to binary CGIHandler().run(app)