python,curl,xml中的变量

时间:2015-10-22 17:44:35

标签: python xml curl

FlushCacheonDP.xml:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
    <m:request xmlns:m="http://www.datapower.com/schemas/management" domain="XXXXX">
        <m:do-action>
            <FlushDocumentCache>
                <XMLManager class="XMLManager">default</XMLManager>
            </FlushDocumentCache>
            <FlushStylesheetCache>
                <XMLManager class="XMLManager">default</XMLManager>
            </FlushStylesheetCache>
        </m:do-action>
    </m:request>
</SOAP-ENV:Body>

我在python脚本中的curl调用中使用它,我的问题是我想用上面的xml调用curl但是domain =“XXXXX”必须从数组中选择不同的字符串。

这就是我如何称呼它:

from sys import argv
import subprocess
# run python cache2.py hosts.txt Test
with open(argv[1]) as f:
addresses = {i.split(" : ")[0] : i.split(" : ")[1] for i in f}
print(addresses[argv[2]])


command = "curl -k --data-binary @FlushCacheonDP.xml -u username@password   https://" +addresses[argv[2]].strip()+ ":5550/service/mgmt/current > Response2\generated_Resp.xml"
print(command)
p = subprocess.Popen(command,shell=True,  stdout=subprocess.PIPE).communicate()[0]

arrayDomain = ['EOT','ITD_TEST',......,'NSO​​PR']

我可以多次调用相同的curl脚本,但它会是一个redandont 谢谢,感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我使用minidom完成了所有设置: .attributes [“domain”]。value = domain  感谢。