title: Python cgi print image to html
body: <p>How to print a png image to html?</p>
  
  <p>I have:</p>
  
  <pre><code>print("Content-Type: image/png\n")
  print(open('image.png', 'rb').read())
  </code></pre>
  
  <p>And it prints that:</p>
  
  <pre><code>Content-Type: image/png
  b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x0 ...
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/18791004/output-binary-data-from-cgi-in-python-3">That</a> answer didn't help me.
  I have this:</p>
  
  <pre><code>Content-Type: image/png �PNG  IHDR�X��%sBIT|d�  pHYsaa�?�i IDAT...
  </code></pre>
  
  <p>HTTP Server:</p>
  
  <pre><code>from http.server import HTTPServer, CGIHTTPRequestHandler
  server_address = ("", 8000)
  httpd = HTTPServer(server_address, CGIHTTPRequestHandler)
  httpd.serve_forever()
  </code></pre>