Ticket ID <type 'exceptions.TypeError'> __init__() got an unexpected keyword argument 'default'

335 views
Skip to first unread message

arutti

unread,
Oct 28, 2013, 12:24:25 AM10/28/13
to web...@googlegroups.com
Hello,

This is a json error which doesn't occur on my dev. system Windows 7, same version of web2py and python2.7

web2py™Version 2.7.4-stable+timestamp.2013.10.14.15.16.29
PythonPython 2.6.6: /usr/languages/python/2.6/bin/python (prefix: /usr/languages/python/2.6)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Traceback (most recent call last):
File "/home/my_site/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/home/my_site/web2py/applications/gps_/controllers/gprs.py", line 126, in <module>
File "/home/my_site/web2py/gluon/globals.py", line 372, in <lambda>
self._caller = lambda f: f()
File "/home/my_site/web2py/applications/gps_/controllers/gprs.py", line 46, in call
def call(): return service()
File "/home/my_site/web2py/gluon/tools.py", line 4913, in __call__
return self.serve_json(request.args[1:])
File "/home/my_site/web2py/gluon/tools.py", line 4604, in serve_json
return response.json(s)
File "/home/my_site/web2py/gluon/globals.py", line 598, in json
return json(data, default=default or custom_json)
File "/home/my_site/web2py/gluon/serializers.py", line 124, in json
default=default).replace(ur'\u2028',
File "/usr/local/lib/python2.6/site-packages/simplejson/__init__.py", line 216, in dumps
**kw).encode(obj)
TypeError: __init__() got an unexpected keyword argument 'default'



This issue raises when I upgraded from web2py-1.99.4 to 2.7.4

To fix the problem, I modified the import of json in gluon/serializers.ps to what it was in 1.99.4 and it works :-)

2.7.4
try:
    import simplejson as json_parser                # try external module
except ImportError:
    try:
        import json as json_parser                  # try stdlib (Python >= 2.6)
    except:
        import gluon.contrib.simplejson as json_parser    # fallback to pure-Python module

1.99.4
try:
    import json as json_parser                      # try stdlib (Python 2.6)
except ImportError:
    try:
        import simplejson as json_parser            # try external module
    except:
        import contrib.simplejson as json_parser    # fallback to pure-Python module


Of course this fix it not satisfactory, because I will have to apply this modification every time I upgrade web2py.
Also I'd like to understand why the problem raises.

Thanks and regards
Andre

Massimo Di Pierro

unread,
Oct 30, 2013, 10:22:03 PM10/30/13
to web...@googlegroups.com
This is not the problem. The problem is that web2py calls json.dumps(..., default=....)
This API is supported by both json and by simplejson (which ships with web2py). The problem is that you have another version of simplejson installed. An older version that does not support this API.

You should uninstall is

    pip uninstall simplejson

The web2py change was motivated by this:

because people usually install simplejson to have a newer version of json, not an older version. ;-)

arutti

unread,
Nov 1, 2013, 4:59:39 AM11/1/13
to web...@googlegroups.com
Thanks Massimo,

In fact this is on a system provided by a ISP, so I don't know how to fix the problem.
I will ask the ISP maintainers.

Regards,
Andre
Reply all
Reply to author
Forward
0 new messages