[mod_python] mod_python and unicode

b3nder b3nder at yandex.ru
Sun Jun 25 08:10:57 EDT 2006


Hi, list.

Tell me please how to use utf-8 in ouput?

from mod_python         import apache
import codecs
import os


def handler(req):
    req.content_type = 'text/plain; charset=utf-8'
    req.send_http_header()
    file = codecs.open(
        os.path.dirname(__file__) + "/myfile.txt", "r", "utf-8")
    a = file.read()
    req.write(a)

    return apache.OK


gives error UnicodeEncodeError: 'ascii' codec can't encode
characters in position 0-5: ordinal not in range(128)

Thanks.


More information about the Mod_python mailing list