Python urllib.request and utf8 decoding question
问题 I'm writing a simple Python CGI script that grabs a webpage and displays the HTML file in the web browser (acting like a proxy). Here is the script: #!/usr/bin/env python3.0 import urllib.request site = "http://reddit.com/" site = urllib.request.urlopen(site) site = site.read() site = site.decode('utf8') print("Content-type: text/html\n\n") print(site) This script works fine when run from the command line, but when it gets to viewing it with a web browser, it shows a blank page. Here is the