zeep SOAP 客户端意外的双 base64 编码
zeep SOAP client unexpected double base64 encoding
请帮助我理解为什么我的请求中的值被编码为 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
python3.7.3
尝试删除字符串中的 encode()
。
request = client.create_message(client.service, 'createHeaderSecurity', message)
Zeep 自动将字节数据编码为 base64。
请帮助我理解为什么我的请求中的值被编码为 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 python3.7.3
尝试删除字符串中的 encode()
。
request = client.create_message(client.service, 'createHeaderSecurity', message)
Zeep 自动将字节数据编码为 base64。