from wsgiref.simple_server import make_server
def application(env, start_response):
response_body = ["%s: %s" % (key, value) for key, value \
in sorted(env.items())]
response_body = '\n'.join(response_body)
status = "200 ok"
response_head = [("ContextType", "text/plain"), ("ContextLength",str(len(response_body)))]
start_response(status, response_head)
return [response_body]
httpd = make_server(
"localhost",
8000,
application
)
httpd.handle_request()
return [response_body]
=>修改为
return [response_body.encode('utf-8')]
运行正常