Can't import gluon.contrib.simplejson after migrating to Python 3

90 views
Skip to first unread message

Lisandro

unread,
Oct 9, 2019, 8:38:35 AM10/9/19
to web2py-users

Hi there! I'm using this version of web2py: Version 2.17.1-stable+timestamp.2018.08.06.01.02.56
I recently moved to Python 3 and I've found this issue. When I try to do this:

from gluon.contrib import simplejson

... I receive this error:

ModuleNotFoundError: No module named 'decoder'


This is the full traceback:

Traceback (most recent call last):
  File "/home/gonguinguen/medios/gluon/custom_import.py", line 98, in custom_importer
    return base_importer(pname, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'applications.webmedios.modules.decoder'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gonguinguen/medios/gluon/custom_import.py", line 102, in custom_importer
    return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'decoder'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gonguinguen/medios/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "/home/gonguinguen/medios/applications/webmedios/controllers/admin.py", line 696, in <module>
  File "/home/gonguinguen/medios/gluon/globals.py", line 421, in <lambda>
    self._caller = lambda f: f()
  File "/home/gonguinguen/medios/applications/webmedios/controllers/admin.py", line 693, in test
    from gluon.contrib import simplejson
  File "/home/gonguinguen/medios/gluon/custom_import.py", line 111, in custom_importer
    return NATIVE_IMPORTER(name, globals, locals, fromlist, level)
  File "/home/gonguinguen/medios/gluon/contrib/simplejson/__init__.py", line 111, in <module>
    from decoder import JSONDecoder, JSONDecodeError
  File "/home/gonguinguen/medios/gluon/custom_import.py", line 104, in custom_importer
    raise ImportError(e1, import_tb)  # there an import error in the module
ImportError: (ModuleNotFoundError("No module named 'applications.webmedios.modules.decoder'",), <traceback object at 0x7f6add36a308>)



Should I install simplejson directly to my virtualenv and avoid using the one provided by web2py?

villas

unread,
Oct 9, 2019, 10:42:30 AM10/9/19
to web...@googlegroups.com
I think we stopped using simplejson some time ago.

Now, when you do this:
from gluon.contrib import simplejson

... this happens ...
from json import *

So, you may as well use the modules of json directly.

Pie

unread,
Oct 13, 2020, 6:25:43 AM10/13/20
to web2py-users
I have the same problem as the OP.  However the function I need to replace is:
gluon.contrib.simplejson.encoder.encode_basestring

What should I replace this with?

villas

unread,
Oct 13, 2020, 4:19:00 PM10/13/20
to web2py-users
I'm not sure what you should replace it with.
I think the only reason why simplejson is no longer distributed with web2py was that the json module became part of the standard library of python.  Therefore,  it did not seem necessary to include it. 
However, if you wish to install simplejson for some reason,  then I don't think there is anything stopping you.
Reply all
Reply to author
Forward
0 new messages