python调用webservice

import requests
#请求的url url
= "http://127.0.0.1:8282/inmesb/service"
# 请求报文
payload = """ <?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:new="http://newimpl.ws.devicequery.shtel.zhongying.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soapenv:Header> <Esb> <Route> <Sender>00119</Sender> <ServCode>021.0001.0.dqPortStatus_new.dqPortStatus_new</ServCode> <MsgId>000000001010111</MsgId> <Time>202102191123</Time> <TransId/> <Version>V0.1</Version> <AuthCode>d30293e619d144fd13d516a87d0d9eae</AuthCode> <AuthType>NONE</AuthType> <MsgType/> <CarryType/> <ServTestFlag/> <MsgType/> </Route> </Esb> </soapenv:Header> <soapenv:Body> <new:queryDevice soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <searchString xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:string"> <![CDATA[ <root> <sessionid>20210111000003</sessionid> <devicename>SH-SH-LC-MSE-4.MAN.M6000</devicename> <deviceip></deviceip> <funccodes> <funccode> <code>dqPortStatus</code> <params> <param name="portDescr" value="xgei-0/6/0/2"/> </params> </funccode> </funccodes> </root> ]]> </searchString> </new:queryDevice> </soapenv:Body> </soapenv:Envelope> """
#请求头
headers = { 'Content-Type': 'application/xml', 'SOAPAction': '' }
#返回报文 response
=requests.post(url=url,headers=headers,data=payload) print(response.text)

注意点:headers头部要加 SOAPAction

posted @ 2021-05-27 13:51  JustInTime  阅读(581)  评论(0)    收藏  举报