Unicode from Web to MySQL

Serge Orlov sombDELETE at pobox.ru
Sun Dec 21 06:36:08 EST 2003


>>Quick scanning of mysql-python docs reveals that you should also
>>call connect with unicode='utf-8' parameter. Have you done that?
>>
> I added that now, but it doesn't seem to make much difference
> (I think it's more for returning data from MySQL, not storing it,
> but that will still be useful)

It's for storing too. If you pass str to .execute it will take the string
and just pass it to MySQL as you created it. But if you use args
parameter of .execute method it will take care of convertions and
escaping. In fact you should pass even ascii strings via args parameter,
if you don't want to deal with escaping yourself.

> I did a test where I grabbed the URL using the same routines and
> dumped the thing to a file, and then edited out all the English and
> various HTML, and the SQL insert works at that point.

It probably contained illegal characters from SQL point of view.

> It seems the mixed language is throwing stuff off, which wouldn't
> bother me if my re.search for only the Vietnamese text were working
> properly, but it isn't.

Why? re.search works fine for my Russian unicode characters.

-- Serge.






More information about the Python-list mailing list