Can't print Chinese to HTTP

Ned Deily nad at acm.org
Mon Nov 30 14:00:12 EST 2009


In article 
<e60da505-ac24-4307-b82e-9257de0fa690 at 1g2000vbm.googlegroups.com>,
 Gnarlodious <gnarlodious at gmail.com> wrote:

> 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.

Are you sure you are actually using Python 3?  /usr/bin/python is the 
path to the Apple-supplied python 2.6.1.  If you installed Python 3.1.1 
using the python.org OS X installer, the path should be 
/usr/local/bin/python3

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list