Catch ExpatError in xmltodict Catch ExpatError in xmltodict xml xml

Catch ExpatError in xmltodict


You need to import the ExpatError from xml.parsers.expact.

from xml.parsers.expat import ExpatError


Found it, within xmltodict module itself, so no need to import it separately from xml module

>>> try:                                             ...     xml_dict = xmltodict.parse(xml_data)... except xmltodict.expat.ExpatError:...     print "that's right"... that's right