I am trying to save the value in Memcache but facing below error for value (for ñ in canada)
"last_name":"Cañada Herrador","personal_space_id":105175
pymemcache.exceptions.MemcacheIllegalInputError: Data values must be binary-safe: ‘ascii’ codec can’t encode character ‘xf1’ in position 61: ordinal not in range(128)
How can I save Unicode characters in memcache, as by default it only supports ASCII char?
2
Answers
You might harness base64 built-in module for this task, but beware that if used with ASCII-only text it will take more space than text itself, consider following example:
You can use
string.encode()
function, but you have to decide how to deal with unicode characters. Here https://docs.python.org/3/howto/unicode.html#converting-to-bytes, you have all the options and explanations.