# Incompatible codecs in module "encodings.utf\_8"

**URL:** <https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [January 23, 2023, 11:29pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945 "2023-01-23T23:29:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgoodwin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgoodwin/32/9734_2.png) [@kgoodwin](https://forum.inductiveautomation.com/u/kgoodwin)\
**Post date:** [January 23, 2023, 11:29pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/1 "2023-01-23T23:29:34Z")

</div>

I wrote a Python package that I am using in Ignition. It works great. I have to add TLS to my communication, it no longer works. I get this error:

`Caused by: org.python.core.PyException: encodings.CodecRegistryError: incompatible codecs in module "encodings.utf_8"`

Is there a way to fix this or an I screwed?

I have an alternative method but it requires `requests` which, when imported throws this error:

`Caused by: org.python.core.PyException: encodings.CodecRegistryError: incompatible codecs in module "encodings.hex_codec"`

If anyone can help that would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 24, 2023, 12:31am UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/2 "2023-01-24T00:31:53Z")

</div>

Use java's tools instead of jython. Python2 has horrible encoding support. Since jython runs in java, it can call java classes to perform network communication with encoding support. Look especially at `system.net.httpClient()`, which has modern TLS support.

(You can probably get the last python2.7 version of requests to work. Others have.)

---

<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:** [January 24, 2023, 12:35am UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/3 "2023-01-24T00:35:34Z")

</div>

This is a known thing with no real satisfactory "fix" beyond, as Phil said, avoiding Jython stdlib stuff. My hunch is that it's a Jython bug we'll have to diagnose and fix.

> [@\[BUG-6135\]CodecRegistryError when importing json library](https://forum.inductiveautomation.com/t/bug-6135-codecregistryerror-when-importing-json-library/34668):
>
> 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,…

---

<div class="post-metadata">

**Author:** ![kgoodwin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgoodwin/32/9734_2.png) [@kgoodwin](https://forum.inductiveautomation.com/u/kgoodwin)\
**Post date:** [January 24, 2023, 9:59pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/4 "2023-01-24T21:59:30Z")

</div>

Ended up making an executable that does everything and just call that from Ignition. Feels like a hack but seems to work pretty good so far.

---

<div class="post-metadata">

**Author:** ![kgoodwin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgoodwin/32/9734_2.png) [@kgoodwin](https://forum.inductiveautomation.com/u/kgoodwin)\
**Post date:** [January 24, 2023, 10:01pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/5 "2023-01-24T22:01:58Z")

</div>

I wasn't using Jythons tools directly. I using a library that is compatible with both 2.7 and 3.10, but not Jython apparently.

I downloaded requests from here `https://pypi.org/project/requests/2.7.0/` and it did not work.

Maybe some other time I'll look into trying to import the Java version of the library and see if I can make that work.

---

<div class="post-metadata">

**Author:** ![kgoodwin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgoodwin/32/9734_2.png) [@kgoodwin](https://forum.inductiveautomation.com/u/kgoodwin)\
**Post date:** [November 14, 2023, 8:12pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/6 "2023-11-14T20:12:42Z")

</div>

This is still a lingering issue for me.

> a Jython bug we'll have to diagnose and fix

The bug and solution is linked in the thread you linked.

> <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):\`

The class Codec is declared as an old-style class without the explicit (object) superclass. If you modify codecs.py in pylib the problem goes away.

Does Inductive maintain their own fork of Jython? If this gets pulled into the primary Jython repo how long would it take to make it into Ignition? Is Jython even maintained at all anymore?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 14, 2023, 9:06pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/7 "2023-11-14T21:06:28Z")

</div>

> [@kgoodwin](#):
>
> Does Inductive maintain their own fork of Jython?

Yes.

> [@kgoodwin](#):
>
> Is Jython even maintained at all anymore?

Yes, but very lightly.

But note, IA (and I) strongly recommend you **not** use the jython stdlib for technology that is present in java's stdlib or in any jar that IA ships with Ignition (quite a few). Jython gives you near-perfect access to everything java can do, with current, supportable functionality. That is the Right Answer™.

---

<div class="post-metadata">

**Author:** ![kgoodwin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgoodwin/32/9734_2.png) [@kgoodwin](https://forum.inductiveautomation.com/u/kgoodwin)\
**Post date:** [November 14, 2023, 9:31pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/8 "2023-11-14T21:31:18Z")

</div>

I am not using the stdlib. I am using a third party python library. I briefly looked into using the java version of the library but from what I understand the jar won't get backedup but the python in site-packages will. I've written java modules for Ignition before but it's a significnaly more painful process for both me and the customer than using Python. I have various work-arounds for this but thought it would be nice to finally get the bug fixed.

---

<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:** [November 14, 2023, 9:49pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/9 "2023-11-14T21:49:38Z")

</div>

I updated our internal ticket to recommend we try out the workaround mentioned in that Github issue. We'll have to do our own testing, but I see no reason we can't make those changes in our fork of Jython.

---

<div class="post-metadata">

**Author:** ![kgoodwin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgoodwin/32/9734_2.png) [@kgoodwin](https://forum.inductiveautomation.com/u/kgoodwin)\
**Post date:** [November 15, 2023, 5:08pm UTC](https://forum.inductiveautomation.com/t/incompatible-codecs-in-module-encodings-utf-8/68945/10 "2023-11-15T17:08:23Z")

</div>

Thanks great! Thanks guys.
