zeep.exceptions.XMLSyntaxError:The root element found is html
zeep.exceptions.XMLSyntaxError:The root element found is html
我正在尝试使用 Zeep 向 Cisco CM 服务器发送 SOAP 请求以进行 MACD 操作,但是出现以下错误:
zeep.exceptions.XMLSyntaxError: 服务器返回的 XML 不包含有效的 {http://schemas.xmlsoap.org/soap/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|project\Path\lib\site-packages\zeep\proxy.py", line 45, in __call__
kwargs,
File "My|project\Path\lib\site-packages\zeep\wsdl\bindings\soap.py", line 130, in send
return self.process_reply(client, operation_obj, response)
File "My|project\Path\lib\site-packages\zeep\wsdl\bindings\soap.py", line 197, in process_reply
result = operation.process_reply(doc)
File "My|project\Path\lib\site-packages\zeep\wsdl\bindings\soap.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
我已经通过 Postman 发出了相同的 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)
我正在尝试使用 Zeep 向 Cisco CM 服务器发送 SOAP 请求以进行 MACD 操作,但是出现以下错误: zeep.exceptions.XMLSyntaxError: 服务器返回的 XML 不包含有效的 {http://schemas.xmlsoap.org/soap/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|project\Path\lib\site-packages\zeep\proxy.py", line 45, in __call__
kwargs,
File "My|project\Path\lib\site-packages\zeep\wsdl\bindings\soap.py", line 130, in send
return self.process_reply(client, operation_obj, response)
File "My|project\Path\lib\site-packages\zeep\wsdl\bindings\soap.py", line 197, in process_reply
result = operation.process_reply(doc)
File "My|project\Path\lib\site-packages\zeep\wsdl\bindings\soap.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 我已经通过 Postman 发出了相同的 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)