zeep.exceptions.XMLSyntaxError:找到的根元素是 html



我正在尝试使用Zeep将SOAP请求发送到Cisco CM服务器以进行MACD操作,但是收到以下错误:zeep.exceptions.XMLSyntaxError:服务器返回的 XML 不包含有效的 {http://schemas.xmlsoap.org/soap/envelope/}Envelope 根元素。找到的根元素是 html

以下是回溯:

Traceback (most recent call last):
File "zeepTest.py", line 39, in <module>
resp = service.listPhone(searchCriteria={'name': 'CIPCDemo1'}, returnedTags={'name':'', 'description':''})
File "My|projectPathlibsite-packageszeepproxy.py", line 45, in __call__
kwargs,
File "My|projectPathlibsite-packageszeepwsdlbindingssoap.py", line 130, in send
return self.process_reply(client, operation_obj, response)
File "My|projectPathlibsite-packageszeepwsdlbindingssoap.py", line 197, in process_reply
result = operation.process_reply(doc)
File "My|projectPathlibsite-packageszeepwsdlbindingssoap.py", line 392, in process_reply
% (envelope_qname.namespace, envelope.tag)
zeep.exceptions.XMLSyntaxError: The XML returned by the server does not contain a valid {http://schemas.xmlsoap.org/soap/envelope/}Envelope root element. The root element found is html

由于此错误没有命中SO,因此我试图理解zeep\wsdl\bindings\soap.py 我已经通过邮递员发出了相同的 SOAP 请求,它可以工作。 我尝试过其他库 (SUDS(,但它们失败了,因为服务器是 SSL 安全的。

这是我的代码:

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 = '<axlusername>'
password = '<password>'
host = '<IP address>'
wsdl = r'my/wsdl/file/path'
location = 'https://{host}:8443/axl'.format(host=host)
binding = r"{http://www.cisco.com/AXLAPIService/}AXLAPIBinding"
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))
resp = service.listPhone(searchCriteria={'name': '<PhoneName'}, returnedTags={'name':'', 'description':''})
print(resp)

预期成果:

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getPhoneResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5">
<return>
<phone ctiid="91" uuid="{A6A03D42-D167-4F64-BE68}">
<name>Phone Name</name>
... data ommited...
</phone>
</return>
</ns:getPhoneResponse>
</soapenv:Body>
</soapenv:Envelope>     

代码中的 AXL URL 似乎缺少尾部斜杠"/"。 您可以尝试添加吗,即:

location = 'https://{host}:8443/axl/'.format(host=host)

最新更新