How do I properly encode something using utf8mb4 in Python?
I am currently trying to migrate my data from Parse onto my own MySQL DB. For one field, on phpmyadmin, I have utf8mb4_unicode_ci as the collation. However, in uploading an emoji in unicode ('\xF0\x9F\x8C\x83') which is the result of:
message = MySQLdb.escape_string(unicode(xstr(data.get('message'))).encode('utf-8'))
where xstr() is:
def xstr(s):
if s is None:
return ''
return s
However, I get an error:
Warning: Incorrect string value: '\xF0\x9F\x8C\x83' for column 'message' at row 1...
I have also tried not using .encode('utf-8'), not using unicode(), etc. Seemingly all combinations. I am now thinking I need to encode the emoji string in utf8mb4 - anybody know how to do this?