Mark Dickinson <[email protected]> added the comment:
I don't think this is a Python bug; it has to do with the stdout
encoding. When connected to a terminal, sys.stdout.encoding is
(probably, on Ubuntu) UTF-8, but when you're using this as a cgi script
it's likely to be defaulting to ascii instead. Not surprisingly, Python
won't let you send non-ASCII characters to a stream whose encoding is
'ascii'.
A workaround is to use sys.stdout.buffer.write (which writes bytes, not
text), and to manually encode your unicode output in whatever encoding
you want ('utf-8', I'm assuming):
>>> sys.stdout.buffer.write('中文\n'.encode('utf8'))
中文
7
----------
nosy: +marketdickinson
resolution: -> invalid
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue6852>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com