Where do you get the error message? What operation is being performed?
C3A6
is the UTF-8 (cf MySQL's utf8 or utf8mb4) hex for æ
; does it seem likely that that was the desired character?
To handle utf8 (or utf8mb4), you need to determine what the client's encoding. Sounds like UTF-8. So, when connecting to MySQL, tell it that -- use these in the connect call:
charset="utf8", use_unicode=True
If the character is in the python source, you need
# -*- coding: utf-8 -*-
at the beginning of the source.
Also the column you are inserting into needs to be CHARACTER SET utf8
(or utf8mb4).
utf8mb4
is needed for Emoji and some of Chinese; otherwise it is 'equivalent' to utf8
.
Do not use decode()
or any other conversion functions; that will just make things harder to fix. In this arena, two wrongs does not make a right; it makes a worse mess.
If you have other symptoms of garbled characters, see Trouble with UTF-8 characters; what I see is not what I stored
To discuss further, please provide the connection call, the SQL statement involved, SHOW CREATE TABLE
, and anything else involved.
C3A6
is a valid utf8/utf8mb4 character æ
, and could be interpreted as valid, though unlikely, latin1 æ
. But it is invalid for CHARACTER SET ascii
. (I don't know how the error message occurred unless the connection said ascii or some obscure charset.)