1
votes

I made this very simple script to test in on browser. setdefaultlanguage was already utf-8

import sys
sys.getdefaultencoding()
f = 'ฟ'
print "Content-Type: text/plain;charset=utf-8"
print f`

The moment I added f = 'some asian text' I always get an error page with IIS - 502 web server received an invalid response. However, the code itself executes and prints the character just fine if I open it with Python IDLE.

Any help greatly appreciate. Thanks!

Additional information: The script is run on Windows Server 2008 R2, IIS 7.5 and WSGI I believe.

1
Please specify the IIS version you are deploying on. Also: how are you serving this Python script (wsgi, cgi,...)? If you change the variable to a simple string like "Hello World", does it work correctly? - chris
Hi Chris. If I change the text to any english character, it works. - Panupat

1 Answers

1
votes

I believe the problem is in your output of HTTP headers. The headers are terminated by a double linefeed (usually "\r\n\r\n"), while you only have a single one. The web server will treat the asian character as part of the HTTP headers (where it is illegal), and thus throw an error.