I have a very long JSON message containing characters that go beyond the limits of an ASCII table. I convert it to a string as follows:
messStr = json.dumps(message,encoding='utf-8', ensure_ascii=False, sort_keys=True)
I need to save this string using a service that limits its size to X bytes. I want to break a JSON string into pieces of length X and store them separately. I ran into some problems doing this (described here ), so I want to compress line cuts to get around these problems. I tried to do this:
ss = mStr[start:fin]
When I do this, I get the following error from zlib.compress :
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 225: ordinal not in range(128)
What is the correct way to compress a UTF-8 string and how to decompress it correctly?
source share