[python-win32] Newbie question. Python asp and diacritic characters
aurora
aurora00 at gmail.com
Mon Dec 19 23:27:34 CET 2005
Do you find any more detail error message than a 500 Server Error?
I have no experience with using Python in the context of ASP. To use
non-ASCII characters correctly requires the understanding of character
encoding and to use them correctly through out a chain of software
components. In your case this might have happended:
1. You use your text editor to write your first version of ASP. It was
saved in encoding X.
2. Python load the code, try to interpret the source code in encoding Y.
3. Calls Response.Write(sGreetings). I guess this would cause the
parameter sGreetings first converted into unicode.
4. IIS spit put to end user in encoding Z.
As you can see there are many places a mismatch can happen. Encoding X
obviously should match encoding Y. I bet a mismatch there cause an 500
error later in step 3.
\xe4 and \xe5 stands for ä and å in latin-1 encoding. Since that work one
thing your can do is to ensure encoding X and encoding Y are all latin-1.
Do you know what character encoding your editor save your file in? I use
an Windows editor called EmEditor, which is especially good in giving your
this kind of detail. After that you still have to make sure Python knows
the encoding you have chosen for step 2. The proper way to do it is
documented in
http://www.python.org/doc/2.4.2/ref/encodings.html
However things maybe different in the ASP context.
That's as far as I can help. Character encoding is really more complicated
than it should be. I hope a few years from now everything would be unicode
and we should not bother by this anymore.
wy
> Hello,
>
> I'm new to Python and also to asp. I started checking those two out just
> a couple of days ago.
>
> Anyway, things seems to work fine except that diacritic characters like
> the Swedish ÅåÄäÖö generate a "HTTP/1.1 500 Server Error".
>
> This example generates the error:
> ------------------------------------
> <%@ LANGUAGE = Python%>
> <html>
> <body>
> <%
> sGreetings = "Hälsningar från Python<br>"
> Response.Write(sGreetings)
> sGreetings = "(Greetings from Python)"
> Response.Write(sGreetings)
> %>
> </body>
> </html>
> ------------------------------------
>
> If I replace the literal diacrites with escape codes for these
> characters, things work allright.
> This code works:
> -----------------------------------
> <%@ LANGUAGE = Python%>
> <html>
> <body>
> <%
> sGreetings = "H\xe4lsningar fr\xe5n Python<br>"
> Response.Write(sGreetings)
> sGreetings = "(Greetings from Python)"
> Response.Write(sGreetings)
> %>
> </body>
> </html>
> -----------------------------------
>
> Is this a bug in the python asp-lib or is there some setting for
> non-english charsets? I do not get this error if I run python as cgi
> with the diacrits included. Also checked that asp under vbscript works
> allright with these characters.
>
> Is there anyone encountered this problem, and perhaps also found a
> solution/workaround?
>
> Best regards,
> Mikael Mikaelsson
> Falu lasarettsbibliotek, Falun, Sweden
More information about the Python-win32
mailing list