SOAP和数组+ SUDS

时间:2012-11-06 12:58:44

标签: soap suds

这是我第一次使用肥皂。

我设法按照教程的第一步,但现在我卡住了。我正在尝试使用螳螂(mantisbt.org)。我试图将这些数据发布到服务器:

<xsd:complexType name="IssueData">
<xsd:all>
<xsd:element name="id" type="xsd:integer" minOccurs="0"/>
<xsd:element name="view_state" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="last_updated" type="xsd:dateTime" minOccurs="0"/>
<xsd:element name="project" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="category" type="xsd:string" minOccurs="0"/>
<xsd:element name="priority" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="severity" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="status" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="reporter" type="tns:AccountData" minOccurs="0"/>
<xsd:element name="summary" type="xsd:string" minOccurs="0"/>
<xsd:element name="version" type="xsd:string" minOccurs="0"/>
<xsd:element name="build" type="xsd:string" minOccurs="0"/>
<xsd:element name="platform" type="xsd:string" minOccurs="0"/>
<xsd:element name="os" type="xsd:string" minOccurs="0"/>
<xsd:element name="os_build" type="xsd:string" minOccurs="0"/>
<xsd:element name="reproducibility" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="date_submitted" type="xsd:dateTime" minOccurs="0"/>
<xsd:element name="sponsorship_total" type="xsd:integer" minOccurs="0"/>
<xsd:element name="handler" type="tns:AccountData" minOccurs="0"/>
<xsd:element name="projection" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="eta" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="resolution" type="tns:ObjectRef" minOccurs="0"/>
<xsd:element name="fixed_in_version" type="xsd:string" minOccurs="0"/>
<xsd:element name="target_version" type="xsd:string" minOccurs="0"/>
<xsd:element name="description" type="xsd:string" minOccurs="0"/>
<xsd:element name="steps_to_reproduce" type="xsd:string" minOccurs="0"/>
<xsd:element name="additional_information" type="xsd:string" minOccurs="0"/>
<xsd:element name="attachments" type="tns:AttachmentDataArray" minOccurs="0"/>
<xsd:element name="relationships" type="tns:RelationshipDataArray" minOccurs="0"/>
<xsd:element name="notes" type="tns:IssueNoteDataArray" minOccurs="0"/>
<xsd:element name="custom_fields" type="tns:CustomFieldValueForIssueDataArray" minOccurs="0"/>
<xsd:element name="due_date" type="xsd:dateTime" minOccurs="0"/>
<xsd:element name="monitors" type="tns:AccountDataArray" minOccurs="0"/>
<xsd:element name="sticky" type="xsd:boolean" minOccurs="0"/>
<xsd:element name="tags" type="tns:ObjectRefArray" minOccurs="0"/>
</xsd:all>
</xsd:complexType>

它运作得很好。但后来我发现我还需要填写一些custom_fields。它们被描述为tns:CustomFieldValueForIssueDataArray。

<xsd:complexType name="CustomFieldValueForIssueDataArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:CustomFieldValueForIssueData[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

我读到它应该包含CustomFieldValueForIssueData对象。

所以我创建了两个带有相关数据的人:

contact_data = client.factory.create('CustomFieldValueForIssueData')
contact_data.field = contact_field
contact_data.value = 'alan@mysite.ee'
client_data = client.factory.create('CustomFieldValueForIssueData')
client_data.field = client_field
client_data.value = u'alan, alan kesselmann'

但是现在如何添加/追加/推送/将这些值添加到数组中?如果我尝试做这样的事情:

issue.custom_fields = [client_field, contact_field]

然后使用:

发布
client.service.mc_issue_add(user, pwd, issue)

然后我得到的只是一个错误。如果没有custom_fields,则ms_issue_add可以正常工作。

艾伦

1 个答案:

答案 0 :(得分:2)

自己想出来......

我必须做的是:

customfields = client.factory.create('CustomFieldValueForIssueDataArray') #had done it before too
customfields.items = [client_data, contact_data] # the new stuff that i didnt know
issue.custom_fields = customfields
client.service.mc_issue_add(user, pwd, issue)

艾伦