CodecRegistryError when importing json library

Hello. I’m having trouble importing the Python json module from within a Python library my team has built, which is installed in the pylib directory. Many times, when this module is imported, the following exception occurs:

  File "D:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\__init__.py", line 108, in <module>
    from .decoder import JSONDecoder
  File "D:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\decoder.py", line 24, in <module>
    NaN, PosInf, NegInf = _floatconstants()
  File "D:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\decoder.py", line 18, in _floatconstants
    _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
  File "user-lib\pylib\encodings\__init__.py", line 142, in search_function
    raise CodecRegistryError,\
CodecRegistryError: incompatible codecs in module "encodings.hex_codec" (D:\Program Files\Inductive Automation\Ignition\user-lib\pylib\encodings\hex_codec$py.class)

This has happened in both Vision and Perspective. The exception doesn’t always occur, but I haven’t been able to pinpoint the exact conditions that cause it to happen. One thing I tried that seemed to help was to add the following import to my library:

import encodings.hex_codec

This “fix” seemed to work in Vision, but it doesn’t seem to be working in Perspective. (My library was working fine in Perspective earlier today, but then this error popped up, and I haven’t been able to fix it.)

Any advice?

Hello,

Any movement on this issue?

I’m seeing the same error in one of my components.

I have tried adding the import encodings.hex_codec statement, and still see the same issue.

Many thanks for any insight you can provide,

-T

I am having a similar problem, when I try to import requests. I am able to import requests in the script console, but when I put it into a change script in perspective, I get the following out of the logger:

Caused by: org.python.core.PyException: Traceback (most recent call last): File “”, line 74, in valueChanged File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests_init_.py”, line 120, in from . import utils File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests\utils.py”, line 27, in from .internal_utils import to_native_string File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests_internal_utils.py”, line 11, in from .compat import is_py2, builtin_str, str File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests\compat.py”, line 31, in import json File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json_init.py", line 108, in from .decoder import JSONDecoder File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\decoder.py”, line 24, in NaN, PosInf, NegInf = _floatconstants() File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\decoder.py”, line 18, in _floatconstants BYTES = ‘7FF80000000000007FF0000000000000’.decode(‘hex’) File "user-lib\pylib\encodings_init.py", line 142, in search_function raise CodecRegistryError,\ encodings.CodecRegistryError: incompatible codecs in module “encodings.hex_codec” (C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\encodings\hex_codec$py.class)

Putting in the import encodings.hex_codec statement doesn’t seem to change anything.

And after a couple of changes, it suddenly started working. I didn’t think those changes would really make a difference, so I pulled them back out adn it still worked.

So it just magically started working ie not throwing that error anymore and doing the GET that I was asking for it to.

That’s a strange one.

Ken

This sounds like similar behavior to what I’ve seen. The import requests works fine in the script console but not in scripts run on the gateway, like a Perspective property change script. Sometimes, though, the opposite has been true. I believe the difference has to do with where the script is being run: locally versus on the gateway.

One thing that sometimes solves the problem sometimes is opening the project properties, making a minor change, and then saving the changes. It seems that this somehow triggers something to be refreshed.