Reputation: 93
I am trying to extract data from a XML file with python. I tried the following code.
from xml.etree.ElementTree import ElementTree
tree = ElementTree()
tree.parse("data_v2.xml")
Error message:
IOError: [Errno 2] No such file or directory: 'data_v2.xml'.
Upvotes: 2
Views: 5971
Reputation: 54292
This is not XML error. This means that data_v2.xml
does not exist -- system (operation system) cannot find it. Maybe this name is wrong, maybe you need to provide full path.
import traceback
# ...
try:
input_fname = "data_v2.xml"
tree.parse(input_fname)
# ...
except IOError:
ex_info = traceback.format_exc()
print('ERROR!!! Cannot parse file: %s' % (input_fname))
print('ERROR!!! Check if this file exists and you have right to read it!')
print('ERROR!!! Exception info:\n%s' % (ex_info))
Upvotes: 9