XML对象在请求之间改变自身

2024-06-16 17:02:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个XML对象

running_config = <data>
    <configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm">
      .
      .
    </configuration>
</data>

The following code works:

rc = self.running_config.find('//config:configuration', namespaces=namespace)


And I can get result:

<configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm"> .. 
</configuration>` 
<br>***Response received on the client***

但这只是第一次 当再次收到相同的请求时,我观察到running_config对象被缩减为<data> </data>(不再存在<configuration>元素)
因此,rc = self.running_config.find('//config:configuration', namespaces=namespace)返回None

Here is my code snippet:

rc = self.running_config.find('//config:configuration', namespaces=namespace)
# check if response is expected in json/xml
root = etree.ElementTree(rpc)
config = root.find('//get-configuration', namespaces=namespace)
if 'format' in config.attrib:
    if config.attrib['format'] == 'xml':
        print 'sending xml response'
        return rc 
#send response in json

我无法理解这里发生了什么


Tags: 对象inselfconfigdataifresponsexml