Recently web2py changed to parse the jsonrpc parameters in
tools.py/Service.serve_jsonrpc. Now I have a frawework in my client
(ember.js) which is sending unicode keys in the jsonrpc parameters. This
causes the code to fail, like this:
{"version": "1.1", "id": "ID1", "error": {"message": "TypeError:
access_view() argument after ** must be a mapping, not unicode", "code":
100, "data": [" File \"/xxx/web2py/gluon/tools.py\", line 4266, in
serve_jsonrpc\n s = methods[method](**params)\n"], "name":
"JSONRPCError"}}
Previously I was "sanitizing" those keys in the controller like this:
def process_json_from_client(**pars):
# I do not know why, but sometimes the keys and values come in unicode
# I will convert all keys to strings, and some values too
# (not all, since sometimes unicode is expected)
sanitized = { }
keys_to_convert = ['cdr_doc_id']
for key, value in pars.iteritems():
key = str(key)
if key in keys_to_convert : value = str(value)
sanitized[str(key)] = value
if __debug__ and SHOW_SANITIZED_PARS: log.warning('sanitized -> %s', gd.
pp.pformat(sanitized))
return sanitized
But since now this is done in tools.py/Service.serve_jsonrpc, I can not
sanitize before calling the jsonrpc controller.
How can unicode keys be accepted in controllers? I think python does not
allow for unicode parameters, right?
--