使用Python Suds和Cisco Axl获得正确的属性嵌套

时间:2014-04-03 18:27:42

标签: python suds cisco-axl

我一直致力于让Cisco Call Manager的AXL使用Python而不是php(我在没有问题的情况下运行),并且遇到了一个问题。我花了好几个小时打击它,所以我认为是时候请求外界意见,看看你是否可以提供任何见解。 我的清理代码如下:

from suds.client import Client
from suds.transport.https import HttpAuthenticated
import logging

logging.basicConfig(level=logging.CRITICAL)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.CRITICAL)
logging.getLogger('suds.xsd.schema').setLevel(logging.CRITICAL)
logging.getLogger('suds.wsdl').setLevel(logging.CRITICAL)

service = 'https://IPADDRESS:PORT/axl/'

wsdl = 'file:///PATH/TO/LOCAL/WSDL/AXLAPI.wsdl'

username = "username"

password = "password"

client = Client(wsdl, location = service, transport = HttpAuthenticated(username = username, password = password))

name = "NAME_DP"

tags = ["regionName"]

print "<THIS IS A LISTDEVICEPOOL REQUEST>"
dp = client.factory.create('ns0:ListDevicePoolReq')
dp.searchCriteria.name = name
dp.returnedTags = tags
result = client.service.listDevicePool(dp)
print "<THIS IS THE RESULT>"
print result

问题是肥皂输出结束了:

DEBUG:suds.client:headers = {'SOAPAction': u'"CUCM:DB ver=8.5 listDevicePool"',
'Content-Type': 'text/xml; charset=utf-8'}
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://www.cisco.com/AXL/API/8.5" xmlns:ns1="http:
//schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchem
a-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <ns1:Body>
      <ns0:listDevicePool>
         <searchCriteria>
            <searchCriteria>
               <name>NAME_DP</name>
            </searchCriteria>
            <returnedTags>regionName</returnedTags>
         </searchCriteria>
      </ns0:listDevicePool>
   </ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:http failed:
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://sc
hemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapen
v:Server</faultcode><faultstring>Usage: Required returnedTags as empty tag or sh
ould contain requested tags</faultstring><detail><axlError><axlcode>5003</axlcod
e><axlmessage>Usage: Required returnedTags as empty tag or should contain reques
ted tags</axlmessage><request>listDevicePool</request></axlError></detail></soap
env:Fault></soapenv:Body></soapenv:Envelope>
Traceback (most recent call last):
  File "C:\Users\C53170\Desktop\sudstest\barebones.py", line 39, in <module>
    result = client.service.listDevicePool(dp)
  File "C:\Python27\lib\site-packages\suds\client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "C:\Python27\lib\site-packages\suds\client.py", line 602, in invoke
    result = self.send(soapenv)
  File "C:\Python27\lib\site-packages\suds\client.py", line 649, in send
    result = self.failed(binding, e)
  File "C:\Python27\lib\site-packages\suds\client.py", line 702, in failed
    r, p = binding.get_fault(reply)
  File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 265, in ge
t_fault
    raise WebFault(p, faultroot)
suds.WebFault: Server raised fault: 'Usage: Required returnedTags as empty tag or should         contain requested tags'

正如您所看到的,它在searchCriteria属性中嵌套了所有内容(包括已定义的searchCriteria),这导致returnsTags属性被视为searchCriteria的一部分。我无法发现原因,或确定如何纠正它。这是wsdl导入方式的问题吗?

如果您需要查看导入的wsdl或xsd文件,请告诉我们。它们非常大,我无法从这台计算机访问pastebin或google文档(在工作时被阻止),但我可以找到一些地方把它们扔掉。

提前感谢您的协助!

1 个答案:

答案 0 :(得分:0)

这是listPhone的代码,但它也适用于listPoolDevice。在我的代码中使用debug和logging命令来查看你的请求在发送时的外观,但我认为这将解决你的问题并让你开始在CUCM和AXL中使用python。

from suds.client import Client

cmserver = '10.10.10.10'
cmport = '8443'
wsdl = 'file:///your/system/path/schema/current/AXLAPI.wsdl'
location = 'https://' + cmserver + ':' + cmport + '/axl/'
username = 'username'
password = 'password'

client = Client(wsdl,location=location, username=username, password=password)

result = client.service.listPhone({'name':'SEP%'},{'name':'','model':''})

for node in result['return']['phone']:
    print str(node['name']), str(node['model'])