English 中文(简体)
统一 错误: 投入说明:“”
原标题:unmarshalling Error: For input string: ""
  • 时间:2011-11-21 12:27:53
  •  标签:
  • python
  • suds

选择<条码> 错误: 投入说明:“。 这可能意味着水桶无法存储数据。 但我的xml格式良好。 为什么在这种xml的轮椅上轮椅?

I am using Suds + python. Here is the wsdl of the soap service:

<xs:element name="parameters">
    <xs:complexType>
    <xs:sequence>
        <xs:element maxOccurs="unbounded" minOccurs="0" name="entry">
            <xs:complexType>
            <xs:sequence>
                <xs:element minOccurs="0" name="key" type="xs:string"/>
                <xs:element minOccurs="0" name="value" type="xs:anyType"/>
            </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
    </xs:complexType>
</xs:element>

甲型六氯环己烷

client = Client(url)
query = client.factory.create( query )
listval1 = {"key":"*:*","value":"*:*"}
query.parameters.entry = [listval1]
response = client.service.search(query)

XML ud:

<query>
   <parameters>
      <entry>
         <key>*:*</key>
         <value>*:*</value>
      </entry>
   </parameters>
</query>

I continue to get unmarshalling Error. Is this because xsi:type="ns0:string" is not added by suds to key and value? If yes then how to add it?

问题回答

i got around this using the a MessagePlugin concept.

from suds.client import Client
from suds.plugin import MessagePlugin

class AnyTypePlugin(MessagePlugin):
    mapping = {
         id :  xsd:int ,
         title :  xsd:string ,
    }
    def marshalled(self, context):
        modified = False

        body = context.envelope.getChild( Body )
        query = body.getChild("query")
        if query: 
            params = query.getChild("parameters")
            if params:
                entries = params.getChildren("entry")
                if entries:
                    for entry in entries:
                        key = entry.getChild("key").getText()
                        if key in self.mapping:
                            attr = Attribute( xsi:type , self.mapping[key])
                            entry.getChild("value").append(attr)
                            modified = True
        if modified:
            xsd_attr = Attribute( xmlns:xsd ,  http://www.w3.org/2001/XMLSchema )
            context.envelope.append(xsd_attr)

url = "some wsdl url"
client = Client(url, plugins=[AnyTypePlugin()])

this way you can control depending on what key you pass as an entry, you can correctly set the type.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签