to use a custom serializer, but with my code below I got this error when
calling n.rpc.service_a.hello("John") from the nameko shell: Can't decode
message body: ContentDisallowed('Refusing to deserialize untrusted content
of type json (application/json)',) (type:u'application/json'
encoding:u'utf-8' raw:'u\'{"args": ["John"], "kwargs": {}}\''')
#custom_serializer.py
import json
from kombu.serialization import register
from nameko.rpc import rpc
def encode(value):
value = json.dumps(value)
return value.upper()
def decode(value):
value = value.lower()
return json.loads(value)
I used this as my config.yaml:
serializer: 'upperjson'
AMQP_URI: 'pyamqp://guest:guest@localhost:5672'
rpc_exchange: 'nameko-rpc'
max_workers: 10
parent_calls_tracked: 10
And ran this:
$ nameko run --config ./config.yaml custom_serializer
I'm running nameko 2.5.1, rabbitmq-server 3.2.4-1, and python 2.7 on Ubuntu
14.04
I'm pretty sure the problem is that your `nameko shell` doesn't have the
custom serializer registered, and so is sending messages with the default
(json) serializer, which your service now doesn't like (since it's
expecting upperjson)
unfortunately, just using the same config.yaml for `nameko shell` also
doesn't work, since it won't be able to find the serializer code and
refuses to start. i guess this is a bug/missing feature. need to think
about how to best load custom code like this into the shell
just to be clear, two regular services can happily communicate using custom
serializers, but the shell currently can't talk to such services
On Thursday, 9 February 2017 06:34:36 UTC, 7oo...@gmail.com wrote:
Hi,
I tried to follow the example here https://github.com/nameko/nameko/blob/master/test/test_serialization.py#L176-L209
to use a custom serializer, but with my code below I got this error when
calling n.rpc.service_a.hello("John") from the nameko shell: Can't decode
message body: ContentDisallowed('Refusing to deserialize untrusted content
of type json (application/json)',) (type:u'application/json'
encoding:u'utf-8' raw:'u\'{"args": ["John"], "kwargs": {}}\''')
#custom_serializer.py
import json
from kombu.serialization import register
from nameko.rpc import rpc
def encode(value):
value = json.dumps(value)
return value.upper()
def decode(value):
value = value.lower()
return json.loads(value)
I used this as my config.yaml:
serializer: 'upperjson'
AMQP_URI: 'pyamqp://guest:guest@localhost:5672'
rpc_exchange: 'nameko-rpc'
max_workers: 10
parent_calls_tracked: 10
And ran this:
$ nameko run --config ./config.yaml custom_serializer
I'm running nameko 2.5.1, rabbitmq-server 3.2.4-1, and python 2.7 on
Ubuntu 14.04