1
votes

Trying to query all items from a mysql (charset:utf8) table which has a field that contains rows with chinese and other special characters I am taking the above error

items = session.query(Item).all()

File "/root/.local/share/virtualenvs/server-WesSANjA/lib/python3.8/site-packages/MySQLdb/cursors.py", line 355, in _post_get_result self._rows = self._fetch_row(0) File "/root/.local/share/virtualenvs/server-WesSANjA/lib/python3.8/site-packages/MySQLdb/cursors.py", line 328, in _fetch_row return self._result.fetch_row(size, self._fetch_type) File "/usr/local/lib/python3.8/encodings/cp1252.py", line 15, in decode return codecs.charmap_decode(input,errors,decoding_table)

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 30: character maps to

1
Did you append ?charset=utf8mb4 to your connection URI as suggested here? - Gord Thompson
@GordThompson yes just right now it worked! - chatzich

1 Answers

2
votes

As described in the documentation here, we need to use ?charset=utf8mb4 for full Unicode support (including emoji):

e = create_engine(
    "mysql+pymysql://scott:tiger@localhost/test?charset=utf8mb4")