[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Can't print Chinese to HTTP
From: exarkun () twistedmatrix ! com
Date: 2009-11-30 19:32:31
Message-ID: 20091130193231.2549.395377677.divmod.xquotient.45 () localhost ! localdomain
[Download RAW message or body]
On 05:05 pm, gnarlodious@gmail.com wrote:
>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('f49\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
As the error suggests, you're writing f49 to the headers section of the
response. This is because you're not ending the headers section with a
blank line. Lines in HTTP end with \r\n, not with just \n.
Have you considered using something with fewer sharp corners than CGI?
You might find it more productive.
Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic