Python XML属性中的sud和名称空间
让肥皂水与NetSuite SOAP API很好地配合使用,我遇到了一些麻烦。我已经使用SoapUI发送了NetSuite XML,该XML适用于我想要的调用,但是我无法让它与Python一起工作。以下是工作XML:Python XML属性中的sud和名称空间,python,soap,suds,Python,Soap,Suds,让肥皂水与NetSuite SOAP API很好地配合使用,我遇到了一些麻烦。我已经使用SoapUI发送了NetSuite XML,该XML适用于我想要的调用,但是我无法让它与Python一起工作。以下是工作XML: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:messages_2015_1.platform.webservices.netsuite.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:messages_2015_1.platform.webservices.netsuite.com"
xmlns:urn1="urn:core_2015_1.platform.webservices.netsuite.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<soapenv:Header>
<urn:preferences>
</urn:preferences>
<urn:partnerInfo>
</urn:partnerInfo>
<urn:applicationInfo>
</urn:applicationInfo>
<urn:passport>
<urn1:email>*****</urn1:email>
<urn1:password>*****</urn1:password>
<urn1:account>*****</urn1:account>
<!--Optional:-->
<urn1:role internalId=*****>
</urn1:role>
</urn:passport>
</soapenv:Header>
<soapenv:Body>
<urn:get>
<urn1:baseRef internalId="2026" type="customer" xsi:type="urn1:RecordRef"/>
</urn:get>
</soapenv:Body>
</soapenv:Envelope>
我已经有五年没有用SOAP做过任何事情了,以前也从来没有用过Python。如有任何建议,将不胜感激 弄明白了,我需要编写一个插件来调用marshalled方法:
class FixXML(suds.plugin.MessagePlugin):
def __init__(self):
pass
def marshalled(self, context):
#the attribute type is really xsi:type, which we need to set but is being handled wrong
#get the Netsuite data type
wsdlDataType = context.envelope.getChild('Body').getChild('get').getChild('baseRef').getAttribute('type').getValue()
#now rewrite xsi:type so its something namespacey
context.envelope.getChild('Body').getChild('get').getChild('baseRef').getAttribute('type').setValue('ns0:RecordRef')
#next we need to add a type attribute without a namespace that contains the data type from the wsdl
typeAttr = suds.sax.attribute.Attribute('type')
typeAttr.setValue(wsdlDataType)
context.envelope.getChild('Body').getChild('get').getChild('baseRef').append(typeAttr)
看起来我需要编写一个插件,在退出时重写内容:
(ReadResponse){
status =
(Status){
_isSuccess = False
statusDetail[] =
(StatusDetail){
_type = "ERROR"
code = "RCRD_TYPE_REQD"
message = "The record type is required."
},
}
}
>>> recordRef
(RecordRef){
name = None
_internalId = 2026
_externalId = ""
_type = "ns1:RecordRef"
}
class FixXML(suds.plugin.MessagePlugin):
def __init__(self):
pass
def marshalled(self, context):
#the attribute type is really xsi:type, which we need to set but is being handled wrong
#get the Netsuite data type
wsdlDataType = context.envelope.getChild('Body').getChild('get').getChild('baseRef').getAttribute('type').getValue()
#now rewrite xsi:type so its something namespacey
context.envelope.getChild('Body').getChild('get').getChild('baseRef').getAttribute('type').setValue('ns0:RecordRef')
#next we need to add a type attribute without a namespace that contains the data type from the wsdl
typeAttr = suds.sax.attribute.Attribute('type')
typeAttr.setValue(wsdlDataType)
context.envelope.getChild('Body').getChild('get').getChild('baseRef').append(typeAttr)