MySQL: 'latin-1' codec can't encode character

Fredrik Lundh fredrik at pythonware.com
Fri May 13 09:37:08 EDT 2005


"francescomoi at europe.com"

> I'm trying to store a text within a MySQL field (v 3.23.58) by using
> MySQLdb
> (v 1.2.1c3).
>
> The text is: "telephone..." (note the last character)
>
> And I get this error message:
> -----------
> File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
> 33, in defaulterrorhandler
>     raise errorclass, errorvalue
> UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2026' in
> position 288: ordinal not in range(256)
> -----------------------
>
> Position 288 is the character I've mentioned. I suppose I must encode
> this caracter
> into a right one which MySQL could store, but I have no idea about how
> to perform
> it. Any suggestion?

the character \u2026 is not part of the ISO-8859-1 character set.  if you
insist on storing that in 8-bit string, you have to find an 8-bit encoding
that includes that character (UTF-8 is one such alternative).

if MySQL is set to store ISO-8859-1 only, you can replace the character
with it with three periods, drop it (use the "ignore" encoding option) or
replace it with a suitable marker (use the "replace" encoding option).

</F>






More information about the Python-list mailing list