【发布时间】:2011-03-27 09:56:16
【问题描述】:
如果我执行以下 Python 3.1 程序,我只会在浏览器中看到 � 而不是正确的字符。文件本身是 UTF-8 编码的,并且与响应一起发送相同的编码。
from wsgiref.simple_server import make_server
page = "<html><body>äöü€ßÄÖÜ</body></html>"
def application(environ, start_response):
start_response("200 Ok", [("Content-Type", "text/html; charset=UTF-8")])
return page
httpd = make_server('', 8000, application)
print("Serving on port 8000...")
httpd.serve_forever()
“UTF-8”在响应中设置正确:
HTTP/1.0 200 Ok
Date: Mon, 09 Aug 2010 16:35:02 GMT
Server: WSGIServer/0.1 Python/3.1.1+
Content-Type: text/html; charset=UTF-8
这里有什么问题?
【问题讨论】:
标签: python http utf-8 character-encoding content-type