Can't print Chinese to HTTP

Gnarlodious gnarlodious at gmail.com
Mon Nov 30 12:05:16 EST 2009


Thanks for the help, but it doesn't work. All I get is an error like:

UnicodeEncodeError: 'ascii' codec can't encode character '\\u0107' in
position 0: ordinal not in range(128)

It does work in Terminal interactively, after I import the sys module.
But my script doesn't act the same. Here is my entire script:

#!/usr/bin/python
print("Content-type:text/plain;charset=utf-8\n\n")
import sys
sys.stdout.buffer.write('晉\n'.encode("utf-8"))

All I get is the despised "Internal Server Error" with Console
reporting:

malformed header from script. Bad header=\xe6\x99\x89

Strangely, if I run the script in Terminal it acts as expected.

This is OSX 10.6 2,, Python 3.1.1.
And it is frustrating because my entire website is hung up on this one
line I have been working on for 5 days.

-- Gnarlie
http://Gnarlodious.com



More information about the Python-list mailing list