I was having issues and looked at the solution for this code on line 32: self.wfile.write(output)
I had to include an .encode() for it to run. I wanted to submit this suggestion. It was the only way I could get my output on the screen.
Line 32: self.wfile.write(output.encode())