In [1]: import asyncio
...: import aiomcache
...:
...: loop = asyncio.get_event_loop()
In [2]: async def hello_aiomcache():
...: mc = aiomcache.Client('127.0.0.1', 11211, loop=loop)
...: await mc.set(bytes('中文', 'utf-8'), b'123')
...:
In [3]: loop.run_until_complete(hello_aiomcache())
---------------------------------------------------------------------------
ValidationException Traceback (most recent call last)
<ipython-input-5-adb51212a606> in <module>
----> 1 loop.run_until_complete(hello_aiomcache())
/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
465 raise RuntimeError('Event loop stopped before Future completed.')
466
--> 467 return future.result()
468
469 def stop(self):
<ipython-input-4-d36e59b6000e> in hello_aiomcache()
1 async def hello_aiomcache():
2 mc = aiomcache.Client('127.0.0.1', 11211, loop=loop)
----> 3 await mc.set(bytes('中文', 'utf-8'), b'123')
4
~/.virtualenvs/lyanna-tp9VnnDu/lib/python3.6/site-packages/aiomcache/client.py in wrapper(self, *args, **kwargs)
18 conn = yield from self._pool.acquire()
19 try:
---> 20 return (yield from func(self, conn, *args, **kwargs))
21 except Exception as exc:
22 conn[0].set_exception(exc)
~/.virtualenvs/lyanna-tp9VnnDu/lib/python3.6/site-packages/aiomcache/client.py in set(self, conn, key, value, exptime)
250 flags = 0 # TODO: fix when exception removed
251 resp = yield from self._storage_command(
--> 252 conn, b'set', key, value, flags, exptime)
253 return resp
254
~/.virtualenvs/lyanna-tp9VnnDu/lib/python3.6/site-packages/aiomcache/client.py in _storage_command(self, conn, command, key, value, flags, exptime, cas)
218 # however custom-compiled memcached can have different limit
219 # so, we'll let the server decide what's too much
--> 220 assert self._validate_key(key)
221
222 if not isinstance(exptime, int):
~/.virtualenvs/lyanna-tp9VnnDu/lib/python3.6/site-packages/aiomcache/client.py in _validate_key(self, key)
54 raise ValidationException('trailing newline', key)
55 else:
---> 56 raise ValidationException('invalid key', key)
57
58 return key
ValidationException: invalid key: b'\xe4\xb8\xad\xe6\x96\x87'
In [4]: debug
> /Users/dongweiming/.virtualenvs/lyanna-tp9VnnDu/lib/python3.6/site-packages/aiomcache/client.py(56)_validate_key()
54 raise ValidationException('trailing newline', key)
55 else:
---> 56 raise ValidationException('invalid key', key)
57
58 return key
ipdb> key
b'\xe4\xb8\xad\xe6\x96\x87'