xml.parsers.expat.ExpatError.code

ExpatError.code

Expat’s internal error number for the specific error. The errors.messages dictionary maps these error numbers to Expat’s error messages. For example:

1
2
3
4
5
6
7
from xml.parsers.expat import ParserCreate, ExpatError, errors
 
p = ParserCreate()
try:
    p.Parse(some_xml_document)
except ExpatError as err:
    print("Error:", errors.messages[err.code])

The errors module also provides error message constants and a dictionary codes mapping these messages back to the error codes, see below.

doc_python
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.