无法在 zeep 中使用 SOAP 服务,python

unable to consume SOAP service in zeep, python

我试图使用 zeep 在 python 中使用 soap 服务。我也使用过 zeep 的几种肥皂服务。但是对于特定的肥皂服务,返回时会出现奇怪的响应,这与组织良好的字典不同。

我的 python 代码如下:

import zeep
import json

def getToken1():
wsdl2 = 'http://trx.*********ast.co.id/Webservice/b******ervice?wsdl'
client2 = zeep.Client(wsdl2)
parameters = {
        'username':'n**l***s',
        'password': 'ra8*******PeSw',
        'counterpart':'***',
        'ipAddress':'127.0.0.1'
}
info = client2.service.requestToken(parameters)
json = zeep.helpers.serialize_object(info, dict)
return json

print(getToken1())

即凭据绝对正确。

不幸的是输出如下:

Traceback (most recent call last):
File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 17, in 
<module>
print(getToken1())
File "F:\Maksudul_Hasan\python\python_soapClient\index.py", line 13, in 
getToken1
info = client2.service.requestToken(parameters)
File 
"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site-                
packages\zeep\proxy.py", line 46, in __call__
return self._proxy._binding.send(
File 
"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site- 
packages\zeep\wsdl\bindings\soap.py", line 135, in send
return self.process_reply(client, operation_obj, response)
File 
"C:\Users\maksudul.it\AppData\Local\Programs\Python\Python39\lib\site- 
packages\zeep\wsdl\bindings\soap.py", line 206, in process_reply
raise TransportError(
zeep.exceptions.TransportError: Server returned response (200) with 
invalid XML: Invalid 
XML content received (AttValue: " or ' expected, line 77, column 14).
Content: b'\n\t\t<html><head><title>NuSOAP: 
Br***stservice</title>\n\t\t<style 
type="text/css">\n\t\t    body    { font-family: arial; color: #000000; 
background-color: 
#ffffff; margin: 0px 0px 0px 0px; }\n\t\t    p       { font-family: 
arial; color: 
#000000; margin-top: 0px; margin-bottom: 12px; }\n\t\t    pre { 
background-color: silver; 
padding: 5px; font-family: Courier New; font-size: x-small; color: 
#000000;}\n\t\t    ul      
....................

这是一个很大的回应。但是在 soapUI 中:

要求:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:urn="urn:SOAPServerWSDL">
<soapenv:Header/>
 <soapenv:Body>
   <urn:requestToken 
  soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <parameters xsi:type="urn:requestTokenCT" 
         xmlns:urn="urn:***stservice">
         <!--You may enter the following 4 items in any order-->
         <username xsi:type="xsd:string">nbl**s</username>
         <password xsi:type="xsd:string">ra8*******4iphEsPeSw</password>
         <counterpart xsi:type="xsd:string">N*L</counterpart>
         <ipAddress xsi:type="xsd:string">127.0.0.1</ipAddress>
      </parameters>
   </urn:requestToken>
 </soapenv:Body>
</soapenv:Envelope>

回复:

<SOAP-ENV:Envelope SOAP- 
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema- 
instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:tns="urn:Brifastservice">
  <SOAP-ENV:Body>
      <ns1:requestTokenResponse xmlns:ns1="urn:SOAPServerWSDL">
         <return xsi:type="tns:requestTokenCTResult">
            <message xsi:type="xsd:string">Success</message>
            <statusCode xsi:type="xsd:string">0**01</statusCode>
            <token 
         xsi:type="xsd:string">99B4631DCD445***23BF6CED31C1B6574</token>
         </return>
      </ns1:requestTokenResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

任何人都可以帮助我通过 python 中的 zeep 从这个 soap 服务获取数据吗?

您请求的 WSDL URL 包含 https 协议并且您正在调用 http 请求。

请称这个url:https://trx.*********ast.co.id/Webservice/b******ervice?wsdl