trying to learn rpc
*controllers/default.py*
from gluon.tools import Service
service = Service()

def call():
    return service()

@service.xmlrpc
@service.jsonrpc
@service.jsonrpc2
def add(a, b):
    return a + b

*using curl*
curl -X GET -d '{"jsonrpc":"2.0","method":"add","params":["1","2"] }' -i 
http://127.0.0.1:8000/test/default/call/jsonrpc2

*result :*
HTTP/1.1 200 OK
X-Powered-By: web2py
Set-Cookie:  
session_id_test=127.0.0.1-e4f82a2b-19ab-4331-9744-711988008e68; httponly; 
Path=/
Expires: Tue, 24 Apr 2018 06:43:49 GMT
Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, 
pre-check=0
Content-Type: application/json; charset=utf-8
Date: Tue, 24 Apr 2018 06:43:49 GMT
Server: Rocket 1.2.6 Python/2.7.10
Content-Length: 0
Connection: keep-alive

*using postman with get method*
http://127.0.0.1:8000/test/default/call/jsonrpc2

*result :*
{"jsonrpc": "2.0", "id": null, "error": {"message": "Parse error. Invalid 
JSON was received by the server.", "code": -32700, "data": "An error 
occurred on the server while parsing the JSON text."}}

*using postman** with get method*
http://127.0.0.1:8000/test/default/call/jsonrpc

*result :*
Traceback (most recent call last):
  File "/Users/MacBookPro/project/python/web2py/gluon/restricted.py", line 
219, in restricted
    exec(ccode, environment)
  File 
"/Users/MacBookPro/project/python/web2py/applications/test/controllers/default.py",
 
line 73, in <module>
  File "/Users/MacBookPro/project/python/web2py/gluon/globals.py", line 
419, in <lambda>
    self._caller = lambda f: f()
  File 
"/Users/MacBookPro/project/python/web2py/applications/test/controllers/default.py",
 
line 64, in call
    return service()
  File "/Users/MacBookPro/project/python/web2py/gluon/tools.py", line 5483, 
in __call__
    return self.serve_jsonrpc()
  File "/Users/MacBookPro/project/python/web2py/gluon/tools.py", line 5207, 
in serve_jsonrpc
    data = json.loads(request.body.read())
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py",
 
line 338, in loads
    return _default_decoder.decode(s)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
 
line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py",
 
line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

any idea?

*n.b.*
web2y latest version scaffolding welcome didn't declare service module in 
db.py

thx and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to