I use xmltodict to parse xml.
If we ExpatError invalid xml, it throws an ExpatError .
How do I catch this? Here is what I tried in my ipython shell
>>> import xmltodict >>> xml_data = """<?xml version="1.0" encoding="UTF-8" ?> ... <Website>""" >>> xml_dict = xmltodict.parse(xml_data) ExpatError: no element found >>> try: ... xml_dict = xmltodict.parse(xml_data) ... except ExpatError: ... print "that right" NameError: name 'ExpatError' is not defined >>> try: ... xml_dict = xmltodict.parse(xml_data) ... except xmltodict.ExpatError: ... print "that right" AttributeError: 'module' object has no attribute 'ExpatError'
mu η‘
source share