JSON-RPC calls within controller functions

55 views
Skip to first unread message

lyn2py

unread,
Jul 8, 2014, 6:41:44 AM7/8/14
to web...@googlegroups.com
I'm wanting to get JSON RPC to work within web2py controller functions, without using pyjamas (which is the example provided in the book)

This is my code for the JSON RPC call:
def test_call():
   
from gluon.contrib.simplejsonrpc import ServerProxy
    service
= ServerProxy('http://127.0.0.1:8000/app22/default/call/jsonrpc')
    result
= service.load(1000)
   
return locals()

(1) Running it within web2py controller functions = It returns an error: ValueError: No JSON object could be decoded

(2) Running it in the browser =  http://127.0.0.1:8000/app22/default/call/jsonrpc/load/1000 it runs into the same error as (1).

(3) Running it in command prompt = it works like a charm.

How do I get it to work within web2py controller functions? Thanks!


Matheus Cardoso

unread,
Jul 9, 2014, 9:58:23 AM7/9/14
to web...@googlegroups.com
There is any authentication on that? If yes, you should try something like this:

server = ServerProxy('http://'+ ws_user + ':' + ws_pass + '@127.0.0.1:8000/app22/default/call/jsonrpc')

And If you created by yourself the WS through web2py, make sure that you put the decorator on your service function "load". Besides, try (this time is a guess, ok?) return your "result" variable instead of locals().

lyn2py

unread,
Jul 10, 2014, 10:21:37 PM7/10/14
to web...@googlegroups.com
Thanks for your response Matheus!

no authentication… is there somewhere I can read up on this? I tried searching around google for answers, and ran into using "id", but no idea how that works, it appears that the id is automatically included. It's working on command line, the exact same commands, but not inside the controller function.

Had me wondering if I am using JSON-RPC correctly?

I guess what I need is an example of JSON-RPC working within a controller's function… 
Reply all
Reply to author
Forward
0 new messages