【问题标题】:AXL Python getLine using pattern instead of uuid does not work (CUCM 11.5)AXL Python getLine 使用模式而不是 uuid 不起作用(CUCM 11.5)
【发布时间】:2018-07-04 11:00:43
【问题描述】:

我正在努力通过 getLine 使用模式而不是 uuid 获取例如行信息。根据 CUCM 11.5 的 getLine AXL 模式,应该可以选择 uuid 或模式作为查找标准。我正在使用的 python (2.7) 模块是 suds-jurko 0.6。

基本代码如下:

from suds.client import Client
import ssl

wsdl = 'file:///C:/Users/xyz/Documents/axlplugin/schema/current/AXLAPI.wsdl'
location = 'https://10.10.20.1/axl/'
username = '***'
password = '***'

ssl._create_default_https_context = ssl._create_unverified_context

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

首先,证明我想用作 getLine 的查找字符串的模式确实存在:

>>> line2 = client.service.listLine({'pattern': '1018'}, returnedTags={'description': ''})
>>> line2
(reply){
return =
(return){
line[] =
(LLine){
_uuid = "{1EC56035-6B5D-283A-4DF0-EFEFA01FCEFF}"
description = None
},
}
}

然后,我尝试使用 uuid 的 getLine,效果很好:

>>> line5 = client.service.getLine('1EC56035-6B5D-283A-4DF0-EFEFA01FCEFF')
>>> line5
(reply){
return =
(return){
line =
(RLine){
_uuid = "{1EC56035-6B5D-283A-4DF0-EFEFA01FCEFF}"
pattern = "1018"
description = None
usage = "Device"
routePartitionName = ""
aarNeighborhoodName = ""

----Rest omitted for brevity---

现在,如果我尝试使用模式而不是 uuid,则会出现以下错误:

line6 = client.service.getLine({'pattern': '1018'}, {'routePartitionName': ''})

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\suds\client.py", line 521, in __call__
return client.invoke(args, kwargs)
File "C:\Python27\lib\site-packages\suds\client.py", line 576, in invoke
soapenv = binding.get_message(self.method, args, kwargs)
File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 109, in get_message
content = self.bodycontent(method, args, kwargs)
File "C:\Python27\lib\site-packages\suds\bindings\document.py", line 95, in bodycontent
add_param, self.options().extraArgumentErrors)
File "C:\Python27\lib\site-packages\suds\argparser.py", line 83, in parse_args
return arg_parser(args, kwargs, extra_parameter_errors)
File "C:\Python27\lib\site-packages\suds\argparser.py", line 108, in __call__
self.__process_parameters()
File "C:\Python27\lib\site-packages\suds\argparser.py", line 299, in __process_parameters
self.__process_parameter(*pdef)
File "C:\Python27\lib\site-packages\suds\argparser.py", line 294, in __process_parameter
self.__in_choice_context(), value)
File "C:\Python27\lib\site-packages\suds\bindings\document.py", line 86, in add_param
p = self.mkparam(method, pdef, value)
File "C:\Python27\lib\site-packages\suds\bindings\document.py", line 130, in mkparam
return Binding.mkparam(self, method, pdef, object)
File "C:\Python27\lib\site-packages\suds\bindings\binding.py", line 225, in mkparam
return marshaller.process(content)
File "C:\Python27\lib\site-packages\suds\mx\core.py", line 59, in process
self.append(document, content)
File "C:\Python27\lib\site-packages\suds\mx\core.py", line 72, in append
self.appender.append(parent, content)
File "C:\Python27\lib\site-packages\suds\mx\appender.py", line 88, in append
appender.append(parent, content)
File "C:\Python27\lib\site-packages\suds\mx\appender.py", line 229, in append
Appender.append(self, child, cont)
File "C:\Python27\lib\site-packages\suds\mx\appender.py", line 168, in append
self.marshaller.append(parent, content)
File "C:\Python27\lib\site-packages\suds\mx\core.py", line 71, in append
if self.start(content):
File "C:\Python27\lib\site-packages\suds\mx\literal.py", line 86, in start
raise TypeNotFound(content.tag)
suds.TypeNotFound: Type not found: 'pattern'

尝试不同的语法也会报错:

line6 = client.service.getLine('1018')
No handlers could be found for logger "suds.client"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\suds\client.py", line 521, in __call__
return client.invoke(args, kwargs)
File "C:\Python27\lib\site-packages\suds\client.py", line 581, in invoke
result = self.send(soapenv)
File "C:\Python27\lib\site-packages\suds\client.py", line 619, in send
description=tostr(e), original_soapenv=original_soapenv)
File "C:\Python27\lib\site-packages\suds\client.py", line 670, in process_reply
raise WebFault(fault, replyroot)
suds.WebFault: Server raised fault: 'Item not valid: The specified Line was not found'

我是否使用了不正确的语法,或者实际上无法使用模式,但是模式文件的状态不同?

另外,我想知道如何从例如 listLine 方法中仅提取 uuid 值,是否可以通过 python axl?

【问题讨论】:

    标签: python suds cucm


    【解决方案1】:

    在 Suds 中,如果我没记错的话,您可以将关键字参数用于获取和更新请求。

    例如:

    resp = client.service.getLine(routePartitionName='PT-ONCLUSTER', pattern='\+49301234567')

    如果这不起作用,请尝试:

    resp = client.service.getLine({'routePartitionName': 'PT-ONCLUSTER', 'pattern': '\+49301234567'})
    

    或者更好的是,改用 python-zeep。它比泡沫更快,维护得更好。 Zeep 的一些示例代码:

    # -*- coding: utf-8 -*-
    
    from zeep import Client
    from zeep.cache import SqliteCache
    from zeep.transports import Transport
    from zeep.exceptions import Fault
    from zeep.plugins import HistoryPlugin
    from requests import Session
    from requests.auth import HTTPBasicAuth
    from urllib3 import disable_warnings
    from urllib3.exceptions import InsecureRequestWarning
    from lxml import etree
    
    
    disable_warnings(InsecureRequestWarning)
    
    username = 'admin'
    password = 'password'
    # If you're not disabling SSL verification, host should be the FQDN of the server rather than IP
    host = '10.1.1.1'
    
    wsdl = 'file://C:/path/to/wsdl/AXLAPI.wsdl'
    location = 'https://{host}:8443/axl/'.format(host=host)
    binding = "{http://www.cisco.com/AXLAPIService/}AXLAPIBinding"
    
    # Create a custom session to disable Certificate verification.
    # In production you shouldn't do this, 
    # but for testing it saves having to have the certificate in the trusted store.
    session = Session()
    session.verify = False
    session.auth = HTTPBasicAuth(username, password)
    
    transport = Transport(cache=SqliteCache(), session=session, timeout=20)
    history = HistoryPlugin()
    client = Client(wsdl=wsdl, transport=transport, plugins=[history])
    service = client.create_service(binding, location)
    
    def show_history():
        for item in [history.last_sent, history.last_received]:
            print(etree.tostring(item["envelope"], encoding="unicode", pretty_print=True))
    
    try:
        resp = service.getLine(pattern='1018', routePartitionName='')
    except Fault:
        show_history()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      • 1970-01-01
      • 2016-01-02
      相关资源
      最近更新 更多