SAX2 driver class org.apache.xerces.parsers.SAXParser

Hi there, yes, I know how to solve this problem :smiley:

Add this code to the top of your script and it will work:

from org.python.core import imp
from java.lang import Thread
Thread.currentThread().setContextClassLoader(imp.getParentClassLoader())

Here is an explanation of the problem and solution:

This is a Classloader problem.

The expat.py module tries to load “org.python.apache.xerces.parsers.SAXParser” before it tries to load “org.apache.xerces.parsers.SAXParser” and fails.

Here’s the code I am talking about:

# Xerces
_mangled_xerces_parser_name = "org.python.apache.xerces.parsers.SAXParser"
_xerces_parser_name = "org.apache.xerces.parsers.SAXParser"
try:
    self._reader = XMLReaderFactory.createXMLReader(_mangled_xerces_parser_name)
except:
    self._reader = XMLReaderFactory.createXMLReader(_xerces_parser_name)

But both the client and designer can import “org.python.apache.xerces.parsers.SAXParser” just fine.

The problem is that the XMLReaderFactory.createXMLReader method in expat.py tries to load “org.python.apache.xerces.parsers.SAXParser” dynamically but looks in the wrong classloaders.

The reason this works in the designer is because in the designer the context classloader is set to a classloader that works. In the client the context classloader is set to null.

So you can get this to work in the client by setting the context classloader to the appropriate classloader.

10 Likes

Hi!

Thank you very much, now the parsing works fine also in the client.

regards
-Heikki

I know this post is a year old, but it solved a problem I had today.

This is such a great resource

Thanks Nick and heikkihe

Fixed the same issues for me 3 years later.

Yep, same issue and successful fix here!

Many years later… this still seems to be a bug in 8.1.1. Should I continue to use the workaround?

Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.7


>>> oc.submit()
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<module:opcenter>", line 501, in submit
  File "<module:opcenter>", line 231, in submit
  File "<module:opcenter>", line 263, in xml
  File "<module:opcenter>", line 291, in dict
  File "<module:opcenter>", line 291, in dict
  File "C:\...\C0\pylib\xmltodict.py", line 295, in parse
    parser = expat.ParserCreate(
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 59, in ParserCreate
    return XMLParser(encoding, namespace_separator)
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 91, in __init__
    self._reader = XMLReaderFactory.createXMLReader(_xerces_parser_name)
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser


	at org.python.core.Py.JavaError(Py.java:552)

	at org.python.core.Py.JavaError(Py.java:543)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)

	at org.python.core.PyObject.__call__(PyObject.java:480)

	at org.python.core.PyObject.__call__(PyObject.java:484)

	at xml.parsers.expat$py.__init__$3(C:/Users/rmclaughlin/.ignition/cache/gwnhigndev.allegro.msad_443/C0/pylib/xml/parsers/expat.py:139)

	at xml.parsers.expat$py.call_function(C:/Users/rmclaughlin/.ignition/cache/gwnhigndev.allegro.msad_443/C0/pylib/xml/parsers/expat.py)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:199)

	at org.python.core.PyFunction.__call__(PyFunction.java:482)

	at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237)

	at org.python.core.PyMethod.__call__(PyMethod.java:228)

	at org.python.core.PyMethod.__call__(PyMethod.java:223)

	at org.python.core.Deriveds.dispatch__init__(Deriveds.java:19)

	at org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java:1112)

	at org.python.core.PyType.type___call__(PyType.java:1880)

	at org.python.core.PyType.__call__(PyType.java:1863)

	at org.python.core.PyObject.__call__(PyObject.java:497)

	at org.python.core.PyObject.__call__(PyObject.java:501)

	at xml.parsers.expat$py.ParserCreate$1(C:/Users/rmclaughlin/.ignition/cache/gwnhigndev.allegro.msad_443/C0/pylib/xml/parsers/expat.py:59)

	at xml.parsers.expat$py.call_function(C:/Users/rmclaughlin/.ignition/cache/gwnhigndev.allegro.msad_443/C0/pylib/xml/parsers/expat.py)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)

	at org.python.core.PyFunction.__call__(PyFunction.java:423)

	at xmltodict$py.parse$12(C:/Users/rmclaughlin/.ignition/cache/gwnhigndev.allegro.msad_443/C0/pylib/xmltodict.py:312)

	at xmltodict$py.call_function(C:/Users/rmclaughlin/.ignition/cache/gwnhigndev.allegro.msad_443/C0/pylib/xmltodict.py)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:132)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.pycode._pyx73.dict$17(<module:opcenter>:293)

	at org.python.pycode._pyx73.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.core.PyFunction.__call__(PyFunction.java:408)

	at org.python.core.PyProperty.property___get__(PyProperty.java:82)

	at org.python.core.PyProperty.__get__(PyProperty.java:71)

	at org.python.core.PyObject.object___findattr__(PyObject.java:3848)

	at org.python.core.PyObject.object___getattribute__(PyObject.java:3832)

	at org.python.core.PyObject$object___getattribute___exposer.__call__(Unknown Source)

	at org.python.core.Deriveds.__findattr_ex__(Deriveds.java:59)

	at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:1036)

	at org.python.core.PyObject.__getattr__(PyObject.java:1025)

	at org.python.pycode._pyx73.xml$15(<module:opcenter>:282)

	at org.python.pycode._pyx73.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)

	at org.python.core.PyFunction.__call__(PyFunction.java:423)

	at org.python.core.PyFunction.__call__(PyFunction.java:418)

	at org.python.core.PyProperty.property___set__(PyProperty.java:95)

	at org.python.core.PyProperty.__set__(PyProperty.java:87)

	at org.python.core.PyObject.object___setattr__(PyObject.java:3884)

	at org.python.core.PyObject.object___setattr__(PyObject.java:3874)

	at org.python.core.PyObject$object___setattr___exposer.__call__(Unknown Source)

	at org.python.core.PyObjectDerived.__setattr__(PyObjectDerived.java:1043)

	at org.python.pycode._pyx73.submit$10(<module:opcenter>:238)

	at org.python.pycode._pyx73.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.core.PyMethod.__call__(PyMethod.java:126)

	at org.python.pycode._pyx73.submit$37(<module:opcenter>:512)

	at org.python.pycode._pyx73.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.core.PyMethod.__call__(PyMethod.java:126)

	at org.python.pycode._pyx75.f$0(<input>:1)

	at org.python.pycode._pyx75.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

	... 83 more

Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)

	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)

	at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.NewInstance.newInstance(Unknown Source)

	... 90 more

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<module:opcenter>", line 501, in submit
  File "<module:opcenter>", line 231, in submit
  File "<module:opcenter>", line 263, in xml
  File "<module:opcenter>", line 291, in dict
  File "<module:opcenter>", line 291, in dict
  File "C:\...\C0\pylib\xmltodict.py", line 295, in parse
    parser = expat.ParserCreate(
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 59, in ParserCreate
    return XMLParser(encoding, namespace_separator)
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 91, in __init__
    self._reader = XMLReaderFactory.createXMLReader(_xerces_parser_name)
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
>>> 

PS - It is very intermittent… maybe 1/100 executions of the same code. Annoying to debug none the less

This is very likely an internal Jython bug; without consistent reproduction it would be very hard for us to fix.

Didn’t think of searching jython bugs…

Looks like this one… Issue 2693: SAXParser, classloader and dynamically loading jython - Jython tracker

I've had a conversation with IA Support about this error recently and they mentioned there are 3 current bug tickets related to this error. They suggested looking for a workaround since one of those tickets date back to 7.7 days.

I've used SAXParser in previous 7.8 and 7.9 gateways without issues and since version 8, it just about fails every time the script runs in the Client but works in the Designer.

Nick's workaround is great.
I found this link yesterday for another work around:

2 Likes

This still seems to work for the same bug in 8.1.5.
Thanks @nmudge

The workaround should no longer be necessary in 8.1.5; we made a change in how the Jython interpreter is loaded that should fix this ‘at the source’:
https://inductiveautomation.com/downloads/releasenotes/8.1.5#16892

2 Likes

So, should this be fixed in all scopes now? I’ll test some more next week for sure when we update to 8.1.6.

So far as we’re aware, anyways… :crossed_fingers:

Hate to be the bearer of bad news… in 8.1.6, still occurring, in the designer script console, seemingly random, but fairly consistent every dozen or so calls, I get the following… Good news, I have not noticed any issues in Perspective sessions after removing the Thread/Classloader snippet.

Java Traceback:
Traceback (most recent call last):
  File "<input>", line 4, in <module>
  File "<module:opcenter>", line 1832, in __init__
  File "<module:opcenter>", line 1846, in cdo
  File "<module:opcenter>", line 430, in cdo_metadata
  File "<module:opcenter>", line 361, in submit_and_return
  File "<module:opcenter>", line 311, in submit
  File "<module:opcenter>", line 591, in xml
  File "<module:opcenter>", line 652, in dict
  File "<module:opcenter>", line 652, in dict
  File "C:\...\C0\pylib\xmltodict.py", line 295, in parse
    parser = expat.ParserCreate(
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 59, in ParserCreate
    return XMLParser(encoding, namespace_separator)
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 91, in __init__
    self._reader = XMLReaderFactory.createXMLReader(_xerces_parser_name)
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser


	at org.python.core.Py.JavaError(Py.java:552)

	at org.python.core.Py.JavaError(Py.java:543)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)

	at org.python.core.PyObject.__call__(PyObject.java:480)

	at org.python.core.PyObject.__call__(PyObject.java:484)

	at xml.parsers.expat$py.__init__$3(C:/.../C0/pylib/xml/parsers/expat.py:139)

	at xml.parsers.expat$py.call_function(C:/.../C0/pylib/xml/parsers/expat.py)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:199)

	at org.python.core.PyFunction.__call__(PyFunction.java:482)

	at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237)

	at org.python.core.PyMethod.__call__(PyMethod.java:228)

	at org.python.core.PyMethod.__call__(PyMethod.java:223)

	at org.python.core.Deriveds.dispatch__init__(Deriveds.java:19)

	at org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java:1112)

	at org.python.core.PyType.type___call__(PyType.java:1880)

	at org.python.core.PyType.__call__(PyType.java:1863)

	at org.python.core.PyObject.__call__(PyObject.java:497)

	at org.python.core.PyObject.__call__(PyObject.java:501)

	at xml.parsers.expat$py.ParserCreate$1(C:/.../C0/pylib/xml/parsers/expat.py:59)

	at xml.parsers.expat$py.call_function(C:/.../C0/pylib/xml/parsers/expat.py)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)

	at org.python.core.PyFunction.__call__(PyFunction.java:423)

	at xmltodict$py.parse$12(C:/.../C0/pylib/xmltodict.py:312)

	at xmltodict$py.call_function(C:/.../C0/pylib/xmltodict.py)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

	at org.python.core.PyFunction.function___call__(PyFunction.java:471)

	at org.python.core.PyFunction.__call__(PyFunction.java:466)

	at org.python.pycode._pyx236.dict$29(<module:opcenter>:654)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.core.PyFunction.__call__(PyFunction.java:408)

	at org.python.core.PyProperty.property___get__(PyProperty.java:82)

	at org.python.core.PyProperty.__get__(PyProperty.java:71)

	at org.python.core.PyObject.object___findattr__(PyObject.java:3848)

	at org.python.core.PyObject.object___getattribute__(PyObject.java:3832)

	at org.python.core.PyObject$object___getattribute___exposer.__call__(Unknown Source)

	at org.python.core.Deriveds.__findattr_ex__(Deriveds.java:59)

	at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:1036)

	at org.python.core.PyObject.__getattr__(PyObject.java:1025)

	at org.python.pycode._pyx236.xml$27(<module:opcenter>:639)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)

	at org.python.core.PyFunction.__call__(PyFunction.java:423)

	at org.python.core.PyFunction.__call__(PyFunction.java:418)

	at org.python.core.PyProperty.property___set__(PyProperty.java:95)

	at org.python.core.PyProperty.__set__(PyProperty.java:87)

	at org.python.core.PyObject.object___setattr__(PyObject.java:3884)

	at org.python.core.PyObject.object___setattr__(PyObject.java:3874)

	at org.python.core.PyObject$object___setattr___exposer.__call__(Unknown Source)

	at org.python.core.PyObjectDerived.__setattr__(PyObjectDerived.java:1043)

	at org.python.pycode._pyx236.submit$11(<module:opcenter>:356)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.core.PyMethod.__call__(PyMethod.java:126)

	at org.python.pycode._pyx236.submit_and_return$12(<module:opcenter>:368)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)

	at org.python.core.PyFunction.__call__(PyFunction.java:413)

	at org.python.core.PyMethod.__call__(PyMethod.java:126)

	at org.python.pycode._pyx236.cdo_metadata$14(<module:opcenter>:465)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:146)

	at org.python.core.PyFunction.__call__(PyFunction.java:423)

	at org.python.core.PyMethod.__call__(PyMethod.java:141)

	at org.python.pycode._pyx236.cdo$101(<module:opcenter>:1852)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:154)

	at org.python.core.PyFunction.__call__(PyFunction.java:423)

	at org.python.core.PyFunction.__call__(PyFunction.java:418)

	at org.python.core.PyProperty.property___set__(PyProperty.java:95)

	at org.python.core.PyProperty.__set__(PyProperty.java:87)

	at org.python.core.PyObject.object___setattr__(PyObject.java:3884)

	at org.python.core.PyObject.object___setattr__(PyObject.java:3874)

	at org.python.core.PyObject$object___setattr___exposer.__call__(Unknown Source)

	at org.python.core.PyObjectDerived.__setattr__(PyObjectDerived.java:1043)

	at org.python.pycode._pyx236.__init__$99(<module:opcenter>:1832)

	at org.python.pycode._pyx236.call_function(<module:opcenter>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:308)

	at org.python.core.PyBaseCode.call(PyBaseCode.java:199)

	at org.python.core.PyFunction.__call__(PyFunction.java:482)

	at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:237)

	at org.python.core.PyMethod.__call__(PyMethod.java:228)

	at org.python.core.PyMethod.__call__(PyMethod.java:223)

	at org.python.core.Deriveds.dispatch__init__(Deriveds.java:19)

	at org.python.core.PyObjectDerived.dispatch__init__(PyObjectDerived.java:1112)

	at org.python.core.PyType.type___call__(PyType.java:1880)

	at org.python.core.PyType.__call__(PyType.java:1863)

	at org.python.core.PyObject.__call__(PyObject.java:480)

	at org.python.core.PyObject.__call__(PyObject.java:484)

	at org.python.pycode._pyx238.f$0(<input>:4)

	at org.python.pycode._pyx238.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:171)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1614)

	at org.python.core.Py.exec(Py.java:1658)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:605)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:593)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

	... 117 more

Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)

	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)

	at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.NewInstance.newInstance(Unknown Source)

	... 124 more

Traceback (most recent call last):
  File "<input>", line 4, in <module>
  File "<module:opcenter>", line 1832, in __init__
  File "<module:opcenter>", line 1846, in cdo
  File "<module:opcenter>", line 430, in cdo_metadata
  File "<module:opcenter>", line 361, in submit_and_return
  File "<module:opcenter>", line 311, in submit
  File "<module:opcenter>", line 591, in xml
  File "<module:opcenter>", line 652, in dict
  File "<module:opcenter>", line 652, in dict
  File "C:\...\C0\pylib\xmltodict.py", line 295, in parse
    parser = expat.ParserCreate(
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 59, in ParserCreate
    return XMLParser(encoding, namespace_separator)
  File "C:\...\C0\pylib\xml\parsers\expat.py", line 91, in __init__
    self._reader = XMLReaderFactory.createXMLReader(_xerces_parser_name)
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)

	at java.xml/org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

Interesting. Can you try boiling that replication down a little? Is it just the script console - you can’t repeat in Vision, for instance? Does a minimal SSCCE like this do it (I can’t replicate it, so I’m trying to isolate the missing factor)?

import xml.etree.ElementTree as ET

ET.fromstring(system.file.readFileAsString("C:\Users\pgriffith\Downloads\simple_script_sfc.xml"))

Ok, spent a bit more time replicating and narrowing down, 8.1.7 BTW. A few things learned:

  • Does not seem to matter reading from file or reading from string
  • If I loop the et.fromstring() it always occurs on the first iteration of the loop (which I guess would be expected with a classloader issue)

Using the following code in script console the java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser consistently occurs anywhere in 1-10 attempts.

import xml.etree.ElementTree as et

# Define as string
xml = """<?xml version="1.0" ?>
<__InSite __encryption="2" __version="1.1">
   <__session>
      <__useSession>
         <user>
            <__name>thedude</__name>
         </user>
         <sessionId __encrypted="no"></sessionId>
      </__useSession>
   </__session>
   <__service __serviceType="OnlineQuery">
      <__utcOffset>+08:00</__utcOffset>
      <__txnGUID>ba55defe-00cc-4b30-888f-8761040294d5</__txnGUID>
      <__inputData>
      
      </__inputData>
      <__requestData>
         <CompletionMsg/>
         <OnlineQuerySelection>
            <__requestSelectionValuesEx/>
         </OnlineQuerySelection>
      </__requestData>
   </__service>
</__InSite>"""

# Read from file
# xml = system.file.readFileAsString(r"C:\temp\debug.xml")

for x in range(10):
	try:
		et.fromstring(xml)
	except:
		raise

I thought it might be something related to project inheritance, so I created a virgin project (no inheritance) and ran this in script console and still occurred regularly. I cleared my .ignition cache and that also did not make any difference.

I created a quick test with an onActionPerformed button in perspective and I cannot replicate the issue, no exceptions, so it seems Perspective context is fine

	import xml.etree.ElementTree as et
	
	# Define as string
	xml = """<?xml version="1.0" ?>
	<__InSite __encryption="2" __version="1.1">
	   <__session>
	      <__useSession>
	         <user>
	            <__name>thedude</__name>
	         </user>
	         <sessionId __encrypted="no"></sessionId>
	      </__useSession>
	   </__session>
	   <__service __serviceType="OnlineQuery">
	      <__utcOffset>+08:00</__utcOffset>
	      <__txnGUID>ba55defe-00cc-4b30-888f-8761040294d5</__txnGUID>
	      <__inputData>
	      
	      </__inputData>
	      <__requestData>
	         <CompletionMsg/>
	         <OnlineQuerySelection>
	            <__requestSelectionValuesEx/>
	         </OnlineQuerySelection>
	      </__requestData>
	   </__service>
	</__InSite>"""
	
	# Read from file
	# xml = system.file.readFileAsString(r"C:\temp\debug.xml")
	
	try:
		x = et.fromstring(xml)
		perspective.statusInfo('%s %s' % (system.date.now(), str(x)))
	except:
		perspective.exceptionError()

Next onto Vision… no issues

So it does seem limited just to script console from what I can tell. Odd part is why can you not replicate it? I just checked the pylib folder to make sure my pylib was the same as the installer and it seems to be.

432 attempts later, I got it to occur on a real build in a Docker container. ~1500 attempts and I still haven't gotten it to happen in a build out of the IDE - that's probably why we're having a hard time replicating in house. The IDE is doing...something, that prevents it from being an issue, and it happens infrequently enough QA didn't hit it on Docker builds. I'll file a new ticket since we've got a good SSCCE now.

Wow, yeah that’s weird the difference in frequency is amazing. Thanks for staying on this, it’s important for us as our MES is all XML communication. Let me know if you need any more info or need fixes tested.

I had this problem and this fix still works for me.

This is still relevant in 8.1.19. I will do some homework and provide details. I've only ever seen this show up in the Script Console. I have a routine that I work with frequently that gets XML data from an API. Doing any manual testing in the script console and I always come across this. The odd thing is it happens twice in a row, then resolves, so the third press of the "Execute" button works. I've dealt with this for probably 18mo now, as it's just a few more clicks.

Edit: Remembered to come back with some detail. The following code is intended to be run from the script console (I'm using a designer connected to a remote Gateway). Provide any xml file. The script will execute as expected 8 consecutive times, fail the 9th and 10th time, then work another 8 times, etc. This pattern is very consistent.

import xml.etree.ElementTree as ET
xmlFile = "C:\Users\user\Downloads\some.xml"
xmlString = system.file.readFileAsString(xmlFile)
root = ET.fromstring(xmlString)
print root.tag

@PGriffith, any further information I could provide?