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 -v http://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/837aa4b3df4c1a93/1bc6d35248d9f9e1?show_docid=1bc6d35248d9f9e1&pli=1
Is there an issue in generic.json ?
Thanks for your help
Seb