Re: 'ascii' codec can't encode character u'\u2013'



Hi.

Thank you both for your answers.

Finally I changed my MySQL table to UTF-8 and changed the structure
of the query (with '%s').

It works. Thank you very much.

2005/9/30, deelan <ggg@xxxxxx>:
> thomas Armstrong wrote:
> (...)
> > when trying to execute a MySQL query:
> > ----
> > query = "UPDATE blogs_news SET text = '" + text_extrated + "'WHERE
> > id='" + id + "'"
> > cursor.execute (query) #<--- error line
> > ----
>
> well, to start it's not the best way to do an update,
> try this instead:
>
> query = "UPDATE blogs_news SET text = %s WHERE id=%s"
> cursor.execute(query, (text_extrated, id))
>
> so mysqldb will take care to quote text_extrated automatically. this
> may not not your problem, but it's considered "good style" when dealing
> with dbs.
>
> apart for this, IIRC feedparser returns text as unicode strings, and
> you correctly tried to encode those as latin-1 str objects before to
> pass it to mysql, but not all glyphs in the orginal utf-8 feed can be
> translated to latin-1. the charecter set of latin-1 is very thin
> compared to the utf-8.
>
> you have to decide:
>
> * switch your mysql db to utf-8 and encode stuff before
> insertion to UTF-8
>
> * lose those characters that cannot be mapped into latin-1,
> using the:
>
> text_extrated.encode('latin-1', errors='replace')
>
> so unrecognized chars will be replaced by ?
>
> also, mysqldb has some support to manage unicode objects directly, but
> things changed a bit during recent releases so i cannot be precise in
> this regard.
>
> HTH.
>
> --
> deelan, #1 fan of adriana lima!
> <http://www.deelan.com/>
>
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
.



Relevant Pages

  • Re: php + mysql multilingual support
    ... > I would recommend storing the Unicode text as UTF-8 as well, ... >> to build in multibyte support for php and mysql. ...
    (comp.lang.php)
  • Re: =?ISO-8859-15?Q?Verst=E4ndnisfrage_zu_Zeichens=E4tzen_bei_?= =?ISO-8859-15?Q?Mys
    ... ich bin gerade etwas verwirrt ob der Zeichensatzmöglichkeiten bei Mysql. ... mit UTF-8 Daten eines Apachen gefüttert wird und das die UTF-8 Daten ... Wenn also deine Daten in der Tabelle als latin1 deklariert ... welches Encoding sie denn für ...
    (de.comp.datenbanken.mysql)
  • Re: Zeichensatz
    ... Ich habe einen englischsprachigen Mann und eine ... englischsprachige Frau (mySQL UTF-8), beide Tragen einen Union Jack um ... PHP sagt MySQL ja gerade nicht, ...
    (de.comp.datenbanken.mysql)
  • Re: Kann keine Umlaute in der DB speichern
    ... dass MySQL bei UTF-8 bis zu ... Zeichen auch mit 1 Byte kodiert wären. ... Latin-1 sowieso nicht darstellen können. ... Wie auch immer: Wenn Du in MySQL ...
    (de.comp.datenbanken.mysql)
  • Re: How to upload form data containing special characters correctly?
    ... See the MySQL doc and comp.databases.mysql newsgroup for more info on mysql topics. ... Well, I've been hearing for a while UTF-8 is the best for all that stuff, so tables and DB's are all in utf8_general_ci ... addslashesis a PHP construct which escapes certain characters. ... I'll rather use OpenOffice with MyODBC to edit the data when needed and use a report to display it. ...
    (comp.lang.php)