zeep SOAP客户端意外的双重base64编码

时间:2019-07-16 21:28:02

标签: python python-3.x soap zeep

请帮助我理解为什么我的请求中的值两次被编码为base64:

我使用的wsdl的相关部分:

<wsdl:types>
      <xsd:schema targetNamespace="http://www.blabla.com/">
         <xsd:element name="createHeaderSecurityRequest" type="xsd:base64Binary"/>

 <wsdl:message name="createHeaderSecurityRequestMessage">
      <wsdl:part element="tns:createHeaderSecurityRequest" name="parameters"/>
   </wsdl:message>

<wsdl:operation name="createHeaderSecurity">
         <wsdl:input message="tns:createHeaderSecurityRequestMessage"/>
         <wsdl:output message="tns:createHeaderSecurityResponseMessage"/>
         <wsdl:fault message="tns:faultMessage" name="createHeaderSecurityFaultMessage"/>
/wsdl:operation>

我的代码:

from zeep import Client
message = 'my message, that needs to be encoded in base64 only once'
wsdl = 'http://xxxxxxx?wsdl'
client = Client(wsdl)
request = client.create_message(client.service, 'createHeaderSecurity', message.encode())

我得到了什么(消息自动编码为base64两次):request =

<soap-env:Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
   <ns0:createHeaderSecurityRequest xmlns:ns0="http://www.blabla.com/">YlhrZ2JXVnpjMkZuWlN3Z2RHaGhkQ0J1WldWa2N5QjBieUJpWlNCbGJtTnZaR1ZrSUdsdUlHSmhjMlUyTkNCdmJteDVJRzl1WTJVPQ==</ns0:createHeaderSecurityRequest>
</soap-env:Body>

我想要什么(仅将消息值编码为base64一次):request =

<soap-env:Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
   <ns0:createHeaderSecurityRequest xmlns:ns0="http://www.blabla.com/">bXkgbWVzc2FnZSwgdGhhdCBuZWVkcyB0byBiZSBlbmNvZGVkIGluIGJhc2U2NCBvbmx5IG9uY2U=</ns0:createHeaderSecurityRequest>
</soap-env:Body>

我将非常感谢您的帮助

zeep 3.4.0 python 3.7.3

1 个答案:

答案 0 :(得分:1)

尝试删除字符串上的encode()

request = client.create_message(client.service, 'createHeaderSecurity', message)

Zeep自动将字节数据编码为base64。