- I make a request which responds in json utf-8 (dict with tupels).
- I'd like to insert the json-response into a mysql database.
- I encode the string with
string.encode('utf-8')
but then the Database, which encodes also in UTF-8 wont insert the correct value.
Without string.encode('utf-8')
i will get an UnicodeEncodeError, so it seems this necessary to encode the string
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 147: ordinal not in range(128)
I make an example:
- string in json: 'quälend'
- string after encode: 'qu\xC3\xA4lend'
- inserted in database: 'quälend'
my guess is, that database handles the encoded utf-8 string still as latin-1, but when I insert some sample utf-8 string which is not encoded, then it works. So the database can handle it right, but just not with the encoded string.
Do you have an idea what the problem might be? I'm loosing my mind about this issue since hours. Any hint is highly appreciated.