1

在尝试使用 Zeep 从 Netsuite Web 服务(WSDL https://webservices.sandbox.netsuite.com/wsdl/v2016_1_0/netsuite.wsdl)创建产品搜索的 SOAP 请求时,我使用以下代码:


result = client.service.search(searchRecord=item_search, _soapheaders={
    'searchPreferences': search_preferences,
    'applicationInfo': app_info,
    'passport': passport,
})

但是 zeep 生成的 XML 格式如下:


<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
   <soap-env:Header>
      <ns0:passport xmlns:ns0="urn:messages_2016_2.platform.webservices.netsuite.com">
         <ns1:email xmlns:ns1="urn:core_2016_2.platform.webservices.netsuite.com">some@email.com</ns1:email>
         <ns2:password xmlns:ns2="urn:core_2016_2.platform.webservices.netsuite.com">somepassword</ns2:password>
         <ns3:account xmlns:ns3="urn:core_2016_2.platform.webservices.netsuite.com">12345</ns3:account>
         <ns4:role xmlns:ns4="urn:core_2016_2.platform.webservices.netsuite.com" internalId="1234" type="role" />
      </ns0:passport>
      <ns5:tokenPassport xmlns:ns5="urn:messages_2016_2.platform.webservices.netsuite.com" />
      <ns6:applicationInfo xmlns:ns6="urn:messages_2016_2.platform.webservices.netsuite.com">
         <ns6:applicationId>ABCDE</ns6:applicationId>
      </ns6:applicationInfo>
      <ns7:partnerInfo xmlns:ns7="urn:messages_2016_2.platform.webservices.netsuite.com" />
      <ns8:searchPreferences xmlns:ns8="urn:messages_2016_2.platform.webservices.netsuite.com">
         <ns8:bodyFieldsOnly>false</ns8:bodyFieldsOnly>
         <ns8:returnSearchColumns>true</ns8:returnSearchColumns>
         <ns8:pageSize>20</ns8:pageSize>
      </ns8:searchPreferences>
   </soap-env:Header>
   <soap-env:Body>
      <ns0:search xmlns:ns0="urn:messages_2016_2.platform.webservices.netsuite.com">
         <ns0:searchRecord xmlns:ns3="urn:common_2016_2.platform.webservices.netsuite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns3:ItemSearchBasic">
            <ns3:isInactive>
               <ns2:searchValue xmlns:ns2="urn:core_2016_2.platform.webservices.netsuite.com">true</ns2:searchValue>
            </ns3:isInactive>
         </ns0:searchRecord>
      </ns0:search>
   </soap-env:Body>
</soap-env:Envelope>

请注意,生成的标头包含我没有设置的参数,例如 tokenPassport 和 partnerInfo。添加的 tokenPassport 与护照一起导致 Netsuite 端点抛出不明确的身份验证错误。

有人可以指出如何从生成的 XML SOAP 标头中删除 tokenPassport 吗?

4

1 回答 1

0

我必须手动删除 tokenPassport 才能让它工作。

# Manually remove tokenPassport that's being incorrectly added by zeep
from lxml import etree
token_passport = envelope.xpath('//x:tokenPassport',
namespaces {'x':'urn:messages_2016_2.platform.webservices.netsuite.com'})
if token_passport:
token_passport[0].getparent().remove(token_passport[0])

https://github.com/procurify/python-zeep/commit/9570007707852caf8e483d4fa9b2b125e73eff1c#diff-e4abfefd4d94bc00a36412733fc6a372

于 2017-01-19T19:47:02.677 回答