[BUG-6135]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.

We’re seeing this as well. A custom package (Mako) works fine in the script console, but fails with the same exception when importing into a Web Dev Python resource file.

We seem to be experiencing the same issue with our perspective deployment. Has there been any resolution that folks have found for this?

We still see this occasionally. From a support ticket from IA, this is the solution that seems to work every time:

We’ve seen this issue get resolved by clearing the jar-cache files in the “data/jar-cache” folder in the Ignition installation directory. This would require a gateway restart, but you could get around restarting the entire gateway by deleting specifically the “com.inductiveautomation.perspective” folder if you’re running Perspective or the “com.inductiveautomation.vision” folder if you are running Vision and then restarting the specific modules in the browser in Config > Modules on the Ignition gateway webpage. Restarting the module will require that you close and restart your current active perspective sessions/vision clients.

It seems that this problem only happens after we update one of our custom Python modules in the pylib folder. To mitigate this issue, we’ve set up our automation that deploys new modules to pylib to stop the gateway, copy the module to pylib, clear the jar-cache files, and then start the gateway.

1 Like

Muchas gracias !

We are still getting this issue repeatedly even after deleting the “com.inductiveautomation.perspective” folder or the entire "data/jar-cache” folder and restarting the gateway. It will work for about a day and then the error message reappears. We’re running 8.1.14.

Same issue… running 8.1.15 - I made a change to my project properties and saved, started working for now.

Is there any solution found you to clear this issue ?
I am also getting the same error when I import requests module in my perspective script

Has anyone in this thread contacted support? Or, even better, isolated reproduction steps?
It does seem like there’s some issue here, but only with custom python libraries?

Actually I need to get the real time weather data of current location. I got the result in python using that same code. But I am getting error while the same script running inside the ignition. I just copied all the libraries from Python directory to Ignition file directory.
But I am getting above mentioned error. Kindly help me solve this issue.

@PGriffith Did you get my point. kindly help me to solve this error

You responded after my working day ended and then bumped this topic before my working day began (yesterday was a holiday).

If you want prompt support, contact support.

1 Like

Yeah, we contacted support, and the response is documented in this post above.

Well, that’s a pretty inadequate response :slight_smile:
Can you DM me your support ticket number?

For posterity: I’ve filed an internal ticket to investigate this issue, because I think the workaround is a poor band-aid masking some real problem.