# \[BUG-6135\]CodecRegistryError when importing json library

**URL:** <https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668>\
**Category:** Ignition\
**Tags:** perspective, vision, scripting, ignition80\
**Created:** [May 12, 2020, 5:48pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668 "2020-05-12T17:48:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alan.s.kinnaman](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@alan.s.kinnaman](https://forum.inductiveautomation.com/u/alan.s.kinnaman)\
**Post date:** [May 12, 2020, 5:48pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/1 "2020-05-12T17:48:10Z")

</div>

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:

```auto
  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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![travis.emery](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@travis.emery](https://forum.inductiveautomation.com/u/travis.emery)\
**Post date:** [May 18, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/2 "2020-05-18T18:45:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [November 20, 2020, 8:06pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/3 "2020-11-20T20:06:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [November 21, 2020, 5:23am UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/4 "2020-11-21T05:23:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alan.s.kinnaman](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@alan.s.kinnaman](https://forum.inductiveautomation.com/u/alan.s.kinnaman)\
**Post date:** [November 23, 2020, 3:16pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/5 "2020-11-23T15:16:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scott.stamps](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@scott.stamps](https://forum.inductiveautomation.com/u/scott.stamps)\
**Post date:** [February 17, 2021, 4:55pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/6 "2021-02-17T16:55:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joey.philippi](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@joey.philippi](https://forum.inductiveautomation.com/u/joey.philippi)\
**Post date:** [February 8, 2022, 2:21pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/7 "2022-02-08T14:21:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alan.s.kinnaman](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@alan.s.kinnaman](https://forum.inductiveautomation.com/u/alan.s.kinnaman)\
**Post date:** [February 8, 2022, 3:23pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/8 "2022-02-08T15:23:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rafael\_rodriguez](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rafael\_rodriguez](https://forum.inductiveautomation.com/u/rafael_rodriguez)\
**Post date:** [February 10, 2022, 7:24pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/9 "2022-02-10T19:24:54Z")

</div>

Muchas gracias !

---

<div class="post-metadata">

**Author:** ![chris.morris](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@chris.morris](https://forum.inductiveautomation.com/u/chris.morris)\
**Post date:** [February 14, 2022, 3:30pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/10 "2022-02-14T15:30:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![todd.messman](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@todd.messman](https://forum.inductiveautomation.com/u/todd.messman)\
**Post date:** [March 15, 2022, 6:11pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/11 "2022-03-15T18:11:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Baskar\_Arumugam](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Baskar\_Arumugam](https://forum.inductiveautomation.com/u/Baskar_Arumugam)\
**Post date:** [May 27, 2022, 9:20am UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/12 "2022-05-27T09:20:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 27, 2022, 3:29pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/13 "2022-05-27T15:29:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Baskar\_Arumugam](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Baskar\_Arumugam](https://forum.inductiveautomation.com/u/Baskar_Arumugam)\
**Post date:** [May 28, 2022, 5:29am UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/14 "2022-05-28T05:29:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Baskar\_Arumugam](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Baskar\_Arumugam](https://forum.inductiveautomation.com/u/Baskar_Arumugam)\
**Post date:** [May 31, 2022, 1:00pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/15 "2022-05-31T13:00:01Z")

</div>

@paul-griffith Did you get my point. kindly help me to solve this error

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 31, 2022, 3:04pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/16 "2022-05-31T15:04:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alan.s.kinnaman](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@alan.s.kinnaman](https://forum.inductiveautomation.com/u/alan.s.kinnaman)\
**Post date:** [May 31, 2022, 3:10pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/17 "2022-05-31T15:10:53Z")

</div>

Yeah, we contacted support, and the response is documented in [this post](https://forum.inductiveautomation.com/t/codecregistryerror-when-importing-json-library/34668/8) above.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 31, 2022, 3:12pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/18 "2022-05-31T15:12:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 31, 2022, 3:30pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/19 "2022-05-31T15:30:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Starlyn\_Olivero](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@Starlyn\_Olivero](https://forum.inductiveautomation.com/u/Starlyn_Olivero)\
**Post date:** [April 24, 2023, 6:07pm UTC](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668/20 "2023-04-24T18:07:08Z")

</div>

The solution is here.

> <https://github.com/jython/jython/issues/96>
>
> An encoding/decoding error has often appeared on jython 2.7.x:
> 
> 07:35:40,977; …\[pool-8-thread-2-\] ERROR com.mediaspectrum.sapix.jython.JythonFactory - encodings.CodecRegistryError: incompatible codecs in module "encodings.hex\_codec" (/opt/wlp/usr/servers/appsrv02/jython/Lib/encodings/hex\_codec.py)
> Traceback (most recent call last):
> File "serverdata.py1612787740532", line 2, in \<module\>
> File "/opt/wlp/usr/servers/appsrv02/jython/Lib/json/\_\_init\_\_.py", line 108, in \<module\>
> from .decoder import JSONDecoder
> File "/opt/wlp/usr/servers/appsrv02/jython/Lib/json/decoder.py", line 24, in \<module\>
> NaN, PosInf, NegInf = \_floatconstants()
> File "/opt/wlp/usr/servers/appsrv02/jython/Lib/json/decoder.py", line 18, in \_floatconstants
> \_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
> File "/opt/wlp/usr/servers/appsrv02/jython/Lib/encodings/\_\_init\_\_.py", line 142, in search\_function
> raise CodecRegistryError,\\
> encodings.CodecRegistryError: incompatible codecs in module "encodings.hex\_codec" (/opt/wlp/usr/servers/appsrv02/jython/Lib/encodings/hex\_codec.py)
> 
> The root of the problem is in jython Library module 'codecs'.
> Class 'Codec' isn't inherited from 'object' one. It leads the functions 'isinstance()', 'hasattr()' etc. return incorrect result for children of this class.
> Adding the inheritance from class 'object' will fix a bug in these functions.
> 
> Line 92 in the 'jython/Lib/codecs.py' file:
> Is:
> \`class Codec:\`
> Should be:
> \`class Codec(object):\`
