2

特殊文字の出力に問題があります。特殊文字を含む単純な文字列を印刷したい場合、ブラウザで python ファイルを開くと、文字列が表示されません。入れてみた

#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-

可能なすべての組み合わせで上に - 機能しませんでした。stdout を使用して文字列を .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"
4

2 に答える 2

0

最後に私は解決策を見つけました:

output = message
json.dumps(output)
return output

動作しませんでした:-)

output = message
return json.dumps(output)

jsonを返す正しい方法です。

于 2013-11-10T12:59:40.280 に答える