2

A python script which parses xml file runs independently fine but when it is called via views.py in flask it throws error. Even trying to parse xml file from views.py itself it throws error. Following are a couple of lines of code which throws error:

 from lxml import etree
 doc1=etree.parse('file.xml')

Error:

IOError: Error reading file 'file.xml': failed to load external entity "file.xml"
2
  • 1
    Does file.xml exist in the CWD of the python process? Does it work if you give it an absolute path? If not, could you share the contents of the xml file? Commented Jul 4, 2013 at 7:47
  • absolute path worked. Thanks :) Commented Jul 4, 2013 at 8:00

1 Answer 1

2

where is your "file.xml" file ?, Put that file where view.py is

Or use absolute path

import os
from lxml import etree

ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
file_path = ROOT_PATH + "/" + "file.xml"
doc1 = etree.parse(file_path)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.