Incompatible codecs in module "encodings.utf_8"

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.

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.)

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.

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.

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.

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.

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?

Yes.

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™.

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.

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.

Thanks great! Thanks guys.