[英]Howto set “text” value for suds webservice object
Suds似乎在解析以下XSD時遇到問題:
<element name="quantity" minOccurs="1" maxOccurs="1">
<annotation>
<documentation>Quantity of this item that's being ordered.</documentation>
</annotation>
<complexType>
<simpleContent>
<extension base="int">
<attribute name="unitOfMeasure" use="required">
<annotation>
<documentation>
Unit of measurement.
The attribute can have the
following values: PCS - pieces
SEC- seconds BYT - bytes KB -
kilobytes
</documentation>
</annotation>
<simpleType>
<restriction base="string">
<enumeration value="PCS" />
<enumeration value="SEC" />
<enumeration value="BYT" />
<enumeration value="KB" />
</restriction>
</simpleType>
</attribute>
</extension>
</simpleContent>
</complexType>
</element>
XML應該看起來像:
<ns0:quantity unitOfMeasure="PCS">1</ns:quantity>
可悲的是,我只能設置屬性:
>>> c.factory.create('ns0:item.quantity')
(quantity){
_unitOfMeasure = ""
}
不可能設置XML節點的“文本”值。
我嘗試過按字面意思創建XML:
element = Element('ns0:quantity')
element.setText("1")
element.set('unitOfMeasure', "PCS")
並將其作為參數傳遞。
這在調試日志記錄中看起來很好(如<ns0:quantity unitOfMeasure="PCS">1</ns0:quantity>
)但實際請求顯示此值將序列化為:
<ns0:quantity />
我迷路了。 如何正確提交此值?
我正在使用泡沫0.4
剛剛找到一個臨時的解決方法。
suds-jurko也會出現這個問題。 雖然suds.client中的漂亮格式日志記錄顯示了XML元素,但suds.transport.http
中的原始日志記錄顯示“plain”輸出無法序列化該元素。
通過啟用client.options.prettyxml = True
可以避免此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.