Worked ! Thanks
On Mar 19, 5:50 am, Massimo Di Pierro <massimo.dipie...@gmail.com> wrote: > return dict(message = db.message(id).as_dict()) > > > > > > > > On Sunday, 18 March 2012 19:10:13 UTC-5, sebsto wrote: > > > Dear All, > > > I am new the web2py and trying to use the relatively new RESTful API, > > as described at > >http://web2py.com/books/default/chapter/29/10#Restful-Web-Services > > > I am testing it with a very simple model : > > db.define_table('message', > > Field('sender', required=True), > > Field('recipient', required=True), > > Field('text', required=True)) > > > And the doc provided function: > > @request.restful() > > def api(): > > response.view = 'generic.json' > > def GET(tablename,id): > > if not tablename=='message': raise HTTP(400) > > return dict(message = db.message(id)) > > return locals() > > > When calling > > curl -vhttp://localhost:8000/RESTtest/default/api/message/1.json > > > It generates an HTTP 500 error and the following ticket is logged > > 1 generic.json TypeError: <function <lambda> at > > 0xa9a72f0> is not > > JSON serializable + details > > > Traceback (most recent call last): > > File "gluon/restricted.py", line 205, in restricted > > File "/Applications/web2py.app/Contents/Resources/applications/ > > RESTtest/views/generic.json", line 2, in <module> > > File "gluon/serializers.py", line 61, in json > > File "gluon/contrib/simplejson/__init__.py", line 270, in dumps > > File "gluon/contrib/simplejson/encoder.py", line 217, in encode > > File "gluon/contrib/simplejson/encoder.py", line 486, in _iterencode > > File "gluon/contrib/simplejson/encoder.py", line 460, in > > _iterencode_dict > > File "gluon/contrib/simplejson/encoder.py", line 460, in > > _iterencode_dict > > File "gluon/contrib/simplejson/encoder.py", line 496, in _iterencode > > File "gluon/serializers.py", line 37, in custom_json > > TypeError: <function <lambda> at 0xa9a72f0> is not JSON serializable > > > Similar problem was reported here > > >http://groups.google.com/group/web2py/browse_thread/thread/837aa4b3df... > > > Is there an issue in generic.json ? > > > Thanks for your help > > > Seb