[mod_python] Params submitted using utf-8

jalil at securia.com jalil at securia.com
Tue Jan 6 17:40:20 EST 2004

    I have a form that submits some text using utf-8 encoding and I 
process the form using  mod_python on Apache.

- When I read in a parameter value and print the type of the string, it 
is "str" and not "unicode". I know unicode is not "utf-8" and I think 
this is fine

- When I try to decode the value into "utf-8" and turn it into unicode 
in python, I get an exception (decoding error - invalid data). Why is 
that? HTML uses Unicode codepoints and I am sending in utf-8 encoding, 
so why I get invalid data?

- The reason I decided doing above is that I have a table in MySQL which 
is using
utf-8 character sets. Everything works fine if I put the received data 
directly into my table and read it back and send it to browser but two 
problems happen if I do this. First, some characters don't display 
right. Second, althought I set the charset in my returned data to utf-8, 
the browser doesn't select utf-8 as encoding. So, I thought maybe I 
should try to convert into unicode b/f putting the data into my table. 
Is this right? Should I  do anything b/f storing and/or sending the data?

I appriciate any help.


More information about the Mod_python mailing list