【问题标题】:Python+SUDS: request as encoding string(base64)Python+SUDS:请求作为编码字符串(base64)
【发布时间】:2012-11-15 21:23:12
【问题描述】:

我正在尝试在 Python 中创建一个客户端,它将与 Web 服务 (NuSoap) 进行通信。标识数据和查询以 XML 格式作为编码字符串 (base64) 发送。 这个 XML 是:

<CV3Data version="2.0">
  <request>
    <authenticate>
      <user>m*****</user>
      <pass>m******</pass>
      <serviceID>b*******0</serviceID>
    </authenticate>
    <requests>
      <reqProducts>
        <reqProductRange start="9294" end="9296"/>
      </reqProducts>
    </requests>
  </request>
</CV3Data>

这个网络服务有这个 wsdl:

<definitions 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="https://service.commercev3.com/CV3Data.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="https://service.commercev3.com/CV3Data.xsd">
 <types>
  <xsd:schema targetNamespace="https://service.commercev3.com/CV3Data.xsd">
   <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
  </xsd:schema>
 </types>    
 <message name="CV3DataRequest">
  <part name="data" type="xsd:base64Binary"/>
 </message>
 <message name="CV3DataResponse">
  <part name="return" type="xsd:base64Binary"/>
 </message>
 <portType name="CV3Data.xsdPortType">
  <operation name="CV3Data">
   <input message="tns:CV3DataRequest"/>
   <output message="tns:CV3DataResponse"/>
  </operation>
 </portType>
 <binding name="CV3Data.xsdBinding" type="tns:CV3Data.xsdPortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="CV3Data">
   <soap:operation soapAction="http://service.commercev3.com/index.php/CV3Data" style="rpc"/>
   <input>
    <soap:body use="encoded" namespace="http://soapinterop.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>
   <output>
    <soap:body use="encoded" namespace="http://soapinterop.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
 </binding>
 <service name="CV3Data.xsd">
  <port name="CV3Data.xsdPort" binding="tns:CV3Data.xsdBinding">
   <soap:address location="http://service.commercev3.com/index.php"/>
  </port>
 </service>
</definitions>

我需要阅读 CV3Data。

【问题讨论】:

  • Base64 是编码,不是加密。
  • 谢谢@ThiefMaster。有什么建议吗?
  • 有什么问题?或者换一种说法:您尝试过什么,又是如何失败的?

标签: python xml base64 suds


【解决方案1】:

要读取“编码”的 XML,您必须“解码”它。 :D

我有一个项目使用带有 EWS 的 suds,我需要下载附件。 EWS 在 Base64Binary 中返回附件,所以我只使用 base64 中的 b64decode 来完成它。像这样的东西应该适合你:

from base64 import b64decode

encoded_xml = NuSoapMethodToGetBase64EncodedXMLString()
decoded_xml = b64decode(CV3Data)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多