How to add an element to a structure in SUDS (python)?

I am creating an AccountAssignment structure

client = suds.client.Client(url) accountAssignment = client.factory.create('AccountAssignment') print accountAssignment 

I get the following result:

 (AccountAssignment){ Key = None AccountNo = None TaxCode = None Debit = None Credit = None Turnover = None Text = None FCDebit = None FCCredit = None FCTurnover = None SummaryAccount = None Balance = None BankNo = None BanksortingCode = None BankAccountNo = None DepositFormNo = None DepositFormDate = None ChequeNumber = None ExpiryDate = None GroupMovementType = None AssociatedCompany = None Comment1 = None Comment2 = None Comment3 = None AdditionalDate1 = None AdditionalDate2 = None } 

Then I can set the desired values ​​and send this structure to the appropriate method. The problem is that two elements are missing in the structure. AccountAssignment should look like this:

 (AccountAssignment){ Key = None AccountNo = None TaxCode = None Debit = None Credit = None Turnover = None Text = None FCDebit = None FCCredit = None FCTurnover = None SummaryAccount = None Balance = None BankNo = None BanksortingCode = None BankAccountNo = None DepositFormNo = None DepositFormDate = None ChequeNumber = None ExpiryDate = None GroupMovementType = None AssociatedCompany = None Comment1 = None Comment2 = None Comment3 = None AdditionalDate1 = None AdditionalDate2 = None DebitSpecified = None ** how to add this? CreditSpecified = None ** how to add this? } 

I tried adding missing elements with MessagePlugin and its marshalled () method. As a result, items are added immediately before sending, which is too late. I need to set values ​​for two missing elements, so the elements must be present before calling the transfer method. I also experimented with InitPlugin and DocumentPlugin, no luck. Any ideas?

Decision:

I solved the problem using DocumentPlugin and implementing my parsed () method. Since no one seems to be interested, I just provide the code, but do not comment on it further. I have lost enough time on this.

 class AccountAssignmentPlugin(suds.plugin.DocumentPlugin): """Plugin to add element to AccountAssignment that is not defined in WSDL.""" def __init__(self, *args): self.args = args def parsed(self, context): # See documentation at http://jortel.fedorapeople.org/suds/doc/suds.sax.element.Element-class.html # and http://jortel.fedorapeople.org/suds/doc/suds.sax.attribute.Attribute-class.html complexTypes = context.document.getRoot().getChild('types').getChild('schema').getChildren('complexType') # Get the complex type with attribute 'name' == 'AccountAssignment'. for ct in complexTypes: if ct.get('name') == 'AccountAssignment': accountAssignment = ct # Get the elements of the AccountAssignment that are used as attributes of the AttributeAssignment object. sequenceElements = accountAssignment.getChild('complexContent').getChild('extension').getChild('sequence') for key in self.args: # Create new element (node) e = suds.sax.element.Element('element') e.setPrefix('s') # Add attributes a = suds.sax.attribute.Attribute('maxOccurs') a.setValue(1) e.append(a) a = suds.sax.attribute.Attribute('type') a.setValue('s:boolean') e.append(a) a = suds.sax.attribute.Attribute('name') a.setValue(key) e.append(a) a = suds.sax.attribute.Attribute('minOccurs') a.setValue(0) e.append(a) sequenceElements.append(e) def transactionService(self): module_name = 'WS3Trans' service_name = 'TransactionService' service_url = '%s/%s/%s.asmx?WSDL' %(self.webservice_url, module_name, service_name) client = suds.client.Client(service_url, plugins=[AccountAssignmentPlugin('DebitSpecified', 'CreditSpecified')]) return client 
+7
python soap xml suds
source share

No one has answered this question yet.

See related questions:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
5116
How to check if a file exists without exceptions?
4473
Calling an external command in Python
4353
How do I pass "Null" (real surname!) To a SOAP web service in ActionScript 3?
3790
How can I safely create a subdirectory?
3602
Does Python have a "contains" substring method?
2601
How can I make a time delay in Python?
2568
How to find out the current time in Python
1782
How can I get the number of items in a list?

All Articles