简体   繁体   English

Python Suds:如何在请求中获取xsd:timeInstant而不是xsd:date?

[英]Python Suds: how to get an xsd:timeInstant instead of xsd:date in request?

I am trying to work with a webservice that needs xsd:timeInstant in a request (see WSDL): 我正在尝试使用在请求中需要xsd:timeInstant的Web服务(请参阅WSDL):

<xsd:complexType name="QueryParams">
       <xsd:all>
            <xsd:element name="start" type="xsd:timeInstant" minOccurs="0"/>
            <xsd:element name="stop" type="xsd:timeInstant" minOccurs="0"/>                    
        </xsd:all>
</xsd:complexType>

The resulting SOAP XML request should therefore contain something like this: 因此,生成的SOAP XML请求应包含以下内容:

<start xsi:type="xsd:timeInstant">2009-05-10T17:00:00Z</start>
<stop xsi:type="xsd:timeInstant">2009-05-11T17:00:00Z</stop>

With SUDS, I created the following object: 使用SUDS,我创建了以下对象:

qp = client.factory.create("ns0:QueryParams")
qp.start = "2009-05-10T17:00:00Z"
qp.stop = "2009-06-10T17:00:00Z"

Unfortunately, SUDS is turning this into an xsd:date which is refused by the server. 不幸的是,SUDS将其转换为xsd:date,服务器拒绝了它。

<query xsi:type="ns3:QueryParams">
    <start xsi:type="ns1:date">2009-05-10T17:00:00Z</start>
    <stop xsi:type="ns1:date">2009-06-10T17:00:00Z</stop>
</query>

Any thoughts how to force an xsd:timeInstant? 有什么想法如何强制xsd:timeInstant?

Think I've found the solution, so might as well post the answer for future reference. 认为我已经找到了解决方案,因此不妨将答案发布以供将来参考。

In the suds/xsd/sxbuiltin.py file, there is a Factory class 在suds / xsd / sxbuiltin.py文件中,有一个Factory类

class Factory:

    tags =\
    {
        # any
        'anyType' : XAny,
        ...
        # dates & times
        ...
        'gMonth' : XString,

Under gMonth, I added 在gMonth下,我添加了

'timeInstant' : XString,

The WSDL type xsd:timeInstant is now copied properly. 现在已正确复制了WSDL类型xsd:timeInstant。 The SOAP request XML shows this: SOAP请求XML显示如下:

<query xsi:type="ns3:QueryParams">
    <start xsi:type="ns1:timeInstant">2009-05-10T17:00:00Z</start>
    <stop xsi:type="ns1:timeInstant">2009-06-10T17:00:00Z</stop>
</query>

And the server is able to handle this input. 服务器可以处理此输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM