无法在Python中分析subprocess.Popen输出中的xml
我正在使用此库解析我的xml:无法在Python中分析subprocess.Popen输出中的xml,python,xml-parsing,subprocess,xml.etree,celementtree,Python,Xml Parsing,Subprocess,Xml.etree,Celementtree,我正在使用此库解析我的xml: import xml.etree.cElementTree as xml 解析器的xml输入是subprocess.Popen的输出: XMLFile = subprocess.Popen(xml_command,shell=True,stdout=subprocess.PIPE, executable="/bin/ksh").communicate()[0] root = xml.XML(XMLFile) 我得到这个错误: IOError: [Errno 3
import xml.etree.cElementTree as xml
解析器的xml输入是subprocess.Popen的输出:
XMLFile = subprocess.Popen(xml_command,shell=True,stdout=subprocess.PIPE, executable="/bin/ksh").communicate()[0]
root = xml.XML(XMLFile)
我得到这个错误:
IOError: [Errno 36] File name too long: ' <?xml version=\...'
试试这个
from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
试试这个
from xml.etree.ElementTree import fromstring
root = fromstring(subprocess.check_output(['/bin/ksh']))
试试这个:
import xml.etree.cElementTree as xml
p = subprocess.Popen(xml_command, shell=True, stdout=subprocess.PIPE, executable="/bin/ksh")
text, err = p.communicate()
root = xml.fromstring(text)
使用python 2.6.6
试试这个:
import xml.etree.cElementTree as xml
p = subprocess.Popen(xml_command, shell=True, stdout=subprocess.PIPE, executable="/bin/ksh")
text, err = p.communicate()
root = xml.fromstring(text)
使用python 2.6.6
您正在将整个xml文件作为文件名传递,所以您遇到了这个错误。请找出如何获取文件名并将其传递到xml.xml
…XMLFile
是xmldata而不是XMLFile这就是为什么我将xml.xml与XMLFile一起使用,并将xml.parse与文件路径一起使用。是否有可能xml\u命令
以某种方式保存xml数据,而错误来自subprocess.Popen()
invocation?我建议在这两行之间放一条调试语句,只是为了再次检查您是否知道异常来自何处-IOError
是一种几乎可以来自任何地方的通用异常。您将整个xml文件作为文件名传递,所以您遇到了这个错误。请找出如何获取文件名并将其传递到xml.xml
…XMLFile
是xmldata而不是XMLFile这就是为什么我将xml.xml与XMLFile一起使用,并将xml.parse与文件路径一起使用。是否有可能xml\u命令
以某种方式保存xml数据,而错误来自subprocess.Popen()
invocation?我建议在这两行之间放一条debug语句,只是为了再次检查您是否知道异常来自哪里-IOError
是一种几乎可以来自任何地方的通用异常。