Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store zlib compressed value #86

Closed
kikdevops opened this issue Jun 9, 2018 · 4 comments
Closed

Store zlib compressed value #86

kikdevops opened this issue Jun 9, 2018 · 4 comments

Comments

@kikdevops
Copy link

I'm trying to set key with zlib compressed value with python3

resp = 'some message'
res = zlib.compress(resp.encode())

mc = aiomcache.Client("slivei_memcached", 11211)
await mc.set(key, res.decode(), 60)
await mc.close()`

and got an error:
'utf-8' codec can't decode byte 0x9c in position 1: invalid start byte

Does anyone know how to solve this problem?

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2018

The library uses text memcache protocol, that's why keys and values are URF-8 encoded.
You can apply base64 encoding as a workaround.

@kikdevops
Copy link
Author

kikdevops commented Jun 9, 2018

I changed code to

resp = 'some message'
res = zlib.compress(resp.encode())
z = base64.b64encode(res)

mc = aiomcache.Client("slivei_memcached", 11211)
await mc.set(key, z, 60)
await mc.close()

but get an error:

'bytes' object has no attribute 'encode'

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2018

Indeed it hasn't. Convert z into a str.

@kikdevops
Copy link
Author

It works, thanks a lot.

    res = zlib.compress(an.encode())
    z = base64.b64encode(z).decode()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants