我在打印特殊字符时遇到问题。如果我想打印一个包含特殊字符的简单字符串,并在浏览器中打开 python 文件,则该字符串不会显示。我试着把
#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-
在所有可能的组合中都处于领先地位 - 没有奏效。我尝试了使用标准输出和使用 .encode('utf8') 对我的字符串进行编码等解决方案。最后一个解决方案对我有帮助,但是我的字符串随后以字节字符串形式呈现,我需要移交 JSON,所以我不想打印带有特殊字符的空白 JSON 字符串。是否有可能是 lighttpd 存在问题,不允许我以 UTF-8 打印?我必须先更改 lighttpd.conf 吗?
Atm 我的配置文件如下所示:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
# "mod_rewrite",
)
server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
" index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" , ".py")
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl"
dir-listing.encoding = "utf-8"
server.dir-listing = "enable"
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "text/plain; charset=utf-8", "text/html; charset=utf-8", "text/css; charset=utf-8", "text/xml; charset=utf-8", "text/javascript; charset=utf-8", "text/x-js", "application/x$
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"