Output binary data from CGI in Python 3
问题 This question is related to this one. I was having no problems while printing raw binary data from a CGI script in Python 2, for example: #!/usr/bin/env python2 import os if __name__ == '__main__': with open(os.path.abspath('test.png'), 'rb') as f: print "Content-Type: image/png\n" print f.read() Here are the relevant response headers: > GET /cgi-bin/plot_string2.py HTTP/1.1 > User-Agent: curl/7.32.0 > Host: 0.0.0.0:8888 > Accept: */* > * HTTP 1.0, assume close after body < HTTP/1.0 200