Cryptic error in lxml when opening file

Dr. John A Zoidberg

My code is rather simple;

f = open(r"C:\filepath\file.xml")
xml = f.read()
tree = etree.parse(xml)

When running this, I get the stack trace

tree = etree.parse(xml)
  File "src/lxml/lxml.etree.pyx", line 3427, in lxml.etree.parse (src\lxml\lxml.etree.c:79801)
  File "src/lxml/parser.pxi", line 1782, in lxml.etree._parseDocument (src\lxml\lxml.etree.c:115995)
  File "src/lxml/parser.pxi", line 1808, in lxml.etree._parseDocumentFromURL (src\lxml\lxml.etree.c:116345)
  File "src/lxml/parser.pxi", line 1712, in lxml.etree._parseDocFromFile (src\lxml\lxml.etree.c:115233)
  File "src/lxml/parser.pxi", line 1115, in lxml.etree._BaseParser._parseDocFromFile (src\lxml\lxml.etree.c:109930)
  File "src/lxml/parser.pxi", line 573, in lxml.etree._ParserContext._handleParseResultDoc (src\lxml\lxml.etree.c:103404)
  File "src/lxml/parser.pxi", line 683, in lxml.etree._handleParseResult (src\lxml\lxml.etree.c:105058)
  File "src/lxml/parser.pxi", line 611, in lxml.etree._raiseParseError (src\lxml\lxml.etree.c:103924)
IOError

What's going on here?

har07

parse() accepts path to the XML file :

tree = etree.parse(r"C:\filepath\file.xml")

Currently your code passes actual content of the XML to parse(), which will trigger such IOError. You can use fromstring() instead to create Element object from a string containing the actual XML data. And if needed, you can then create an ElementTree object from previously created Element :

f = open(r"C:\filepath\file.xml")
xml = f.read()
root = etree.fromstring(xml)
tree = etree.ElementTree(root)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error when opening saved file

From Dev

Using AWK to Retrieve an Error in a Cryptic Log File

From Dev

Cryptic Error When Attempted to Sign Kernel Modules

From Dev

Encoding error when opening an Excel file with xlrd

From Dev

Emacs polymode gives error when opening file

From Dev

Error when opening file for reading in c#

From Dev

XML file to Excel, error when opening

From Dev

phpexcel Fatel Error when opening file

From Dev

Memory error when opening the file with read()

From Dev

Opening BBC XML file in Python using urllub2 and lxml gives me 406 error

From Dev

Libgdx: File not found error 'Internal' when opening external file

From Dev

Error when opening Ruby File (Beginner) + How to run a file?

From Dev

Libgdx: File not found error 'Internal' when opening external file

From Dev

Cryptic error message when passing const parameters as arguments

From Dev

SQLiteManager: Error in opening file?

From Dev

Error handling in file opening

From Dev

Opening a file with a name error

From Dev

PHP file opening error

From Dev

PHP file opening error

From Dev

Error, opening json file

From Dev

PHP .zip file download error when opening in windows explorer

From Dev

Prevent Error Message from Appearing When Hitting Cancel of Opening a File

From Dev

File contains corrupted data error when opening Excel sheet with OpenXML

From Dev

Error when "Cancel" while opening a file in PyQt4

From Dev

PHP .zip file download error when opening in windows explorer

From Dev

ECCODES ERROR when opening .GRIB file in Spyder and in Visual Studio Code

From Dev

Cryptic error pertaining to SMTPRecipientsRefused

From Dev

Cryptic error messages

From Dev

cryptic LDA plotting error

Related Related

HotTag

Archive