You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The expat parser in xml.parsers.expat has a Parse method and a ParseFile method. The Parse method parses a string, however the ParseFile method wants bytes.
This is a minimal example of the Parse method:
>> import xml.parsers.expat
>> p = xml.parsers.expat.ParserCreate()
>> p.Parse('<?xml version="1.0"?>')
which runs fine. Note that argument to p.Parse is a string, not bytes.
@michiel I'm sorry about the delay in replying to you. I can confirm the same behaviour in 3.4.1 on 3.5.0a0 on Windows 7.
sbardeau commented on Oct 14, 2014
sbardeaumannequin
Mannequin
More actions
Same problem here with:
Python 3.4.1 (default, Jul 30 2014, 14:02:54)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
What is unclear to me if this is a bug or a feature. In particular, as described here http://stackoverflow.com/questions/1179305/expat-parsing-in-python-3, one can open the xml file as binary to solve the issue. But is this /really/ intended? Opening standard ASCII xml files as binaries!?
ParseFile() supports only binary files, which is now stated explicitly in the documentation (gh-156821, GH-156822). Adding support of text files (if anybody needs this) is a separate issue.
Activity
mdehoon commentedon Dec 19, 2012
The expat parser in xml.parsers.expat has a Parse method and a ParseFile method. The Parse method parses a string, however the ParseFile method wants bytes.
This is a minimal example of the Parse method:
which runs fine. Note that argument to p.Parse is a string, not bytes.
This is the corresponding example of ParseFile:
where the file test.xml only contains <?xml version="1.0"?>
This gives an error:
Opening the file test.xml in binary raises an Error:
suggesting that in reality, the expat Parser needs a string, not bytes.
(the same error appears with a more meaningful XML file).
I would expect that both Parse and ParseFile accept strings, but not bytes.
BreamoreBoy commentedon Jul 13, 2014
@michiel I'm sorry about the delay in replying to you. I can confirm the same behaviour in 3.4.1 on 3.5.0a0 on Windows 7.
sbardeau commentedon Oct 14, 2014
Same problem here with:
Python 3.4.1 (default, Jul 30 2014, 14:02:54)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
What is unclear to me if this is a bug or a feature. In particular, as described here http://stackoverflow.com/questions/1179305/expat-parsing-in-python-3, one can open the xml file as binary to solve the issue. But is this /really/ intended? Opening standard ASCII xml files as binaries!?
iritkatriel commentedon Nov 28, 2021
Reproduced on 3.11.
serhiy-storchaka commentedon Sep 2, 2026
ParseFile()supports only binary files, which is now stated explicitly in the documentation (gh-156821, GH-156822). Adding support of text files (if anybody needs this) is a separate issue.