Python Zeep错误消息无法处理

2024-05-19 10:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用来自外部SOAP API的操作。这个API没有文档,所以我大部分时间都不知道。我收到一个在soapapi中工作的请求,所以我想尝试在Python中进行集成

我的zeep:

wsdl = 'https://asp.external.se/apps/api/service.svc?wsdl'
token = UsernameToken('username', 'password')
client = Client(wsdl=wsdl, wsse=token)
client.service.GetCompanies()

我可以通过client.services进行制表并查看所有操作,因此我知道WSDL的设置是正确的。 但无论我尝试调用什么操作,都会出现此错误:

Fault: The message could not be processed. This is most likely because the action 'www.external.com/services/apiservice/GetCompanies' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.

我能想到的一件事是,在SOAP UI中工作的端点不是WSDL的默认端点,我必须手动在SOAP UI中添加“/endpoint2”。我不确定我是否能在zeep中做同样的事情

以下是在SOAP UI中工作的原始信封:

POST www.external.com/services/apiservice/endpoint2
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ".../GetCompanies"
Authorization: Basic Zm9hLWFwaTpGXFGUw==
Content-Length: 1030
Host: asp.external.se
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bril="www.external.com/services/apiservice">
   <soapenv:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:mustUnderstand="1">
         <wsse:UsernameToken wsu:Id="UsernameToken-DE48543B99D24B1D1597402523">
            <wsse:Username></wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"></wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">arhKkjhdKuO9yGGw==</wsse:Nonce>
            <wsu:Created>2020-08-19T09:59:34.025Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <a:GetCompanies />
   </soapenv:Body>
</soapenv:Envelope>

Tags: theorgtokenapihttpservicesoapexternal

热门问题