help with jsonrpc

43 views
Skip to first unread message

Trevor Overman

unread,
Mar 1, 2014, 2:46:59 PM3/1/14
to web...@googlegroups.com
So I'm trying to connect an android application to my web2py website back end database by using json remote procedure calls.
Currently, I am trying to make a simple test function to remotely add entries in the db.
Additionally, I am running on GAE.

What I have right now is:

db.py
db.define_table('testing',
   
Field('number_sum','string'),
)

default.py
def call():
   
return service()

@service.jsonrpc
def test_add(a,b):
    sum
= a+b
    db
.testing.insert(numer_sum=sum)
   
return a+b

when I run the following in terminal,
curl http://domain/app/default/call/run/test_add?a=3&b=4

I receive an "Object does not exist" error.
Any help would be appreciated!

-Trevor

Anthony

unread,
Mar 1, 2014, 3:51:32 PM3/1/14
to web...@googlegroups.com
db.testing.insert(numer_sum=sum)

Shouldn't the above be number_sum?

Trevor Overman

unread,
Mar 1, 2014, 6:18:54 PM3/1/14
to web...@googlegroups.com
ah you're right.. x.x...
unfortunately, I am still receiving the same error.
Another thing, when I try accessing the url with a specific port, ex. http://domain:port/app/default/call/run/test_add?a=3&b=4 GAE is sending me a timeout error. hmm...

Jonathan Lundell

unread,
Mar 1, 2014, 6:32:35 PM3/1/14
to web2py
Change 'run' to 'jsonrpc', since that's how you declared test_add. But curl isn't going to create a jsonrpc request for you, so that part won't work.

If you want the curl request to work (with /run/), you need @service.run rather than @service.jsonrpc.


Trevor Overman

unread,
Mar 1, 2014, 7:34:42 PM3/1/14
to web...@googlegroups.com
Finally got things working. For anyone out there reading this, I fixed the problem by utilizing urlfetch in GAE.

@service.jsonrpc
def test_add(a,b):
    number_sum
= a+b
    db
.testing.insert(number_sum=number_sum)
   
return a+b

def test():
   
from gluon.contrib.simplejsonrpc import ServerProxy
    from google.appengine.api import urlfetch
    URL
= "http://www.conex.us/conexus/default/call/jsonrpc"
    urlfetch.set_default_fetch_deadline(60)
    service
= ServerProxy(URL, verbose=True)
    test
= service.test_add(1, 2)
   
return test

Anyway, thanks for the help! :)

Dave S

unread,
Mar 3, 2014, 2:26:28 PM3/3/14
to web...@googlegroups.com


On Saturday, March 1, 2014 4:34:42 PM UTC-8, Trevor Overman wrote:
Finally got things working. For anyone out there reading this, I fixed the problem by utilizing urlfetch in GAE.

Works with curl, or works with your Android app?

In either case, thanks for the update!

/dps

Reply all
Reply to author
Forward
0 new messages