SOAP请求中的TypeError(使用pysimplesoap)

2024-10-08 18:30:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从荷兰政府土地登记处(WSDL here)和PySimpleSoap)的SOAP服务获取相关信息。到目前为止,我成功地使用以下代码连接并请求有关特定属性的信息:

from pysimplesoap.client import SoapClient
client = SoapClient(wsdl='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl', username='xxx', password='xxx', trace=True)

response = client.VerzoekTotInformatie(
    Aanvraag={
        'berichtversie': '4.7',  # Refers to the schema version
        'klantReferentie': klantReferentie,  # A reference we can set ourselves.
        'productAanduiding': '1185',  # a four-digit code referring to whether the response should be in "XML" (1185), "PDF" (1191) or "XML and PDF" (1057).
        'Ingang': {
            'Object': {
                'IMKAD_KadastraleAanduiding': {
                    'gemeente': 'ARNHEM AC',  # municipality
                    'sectie': 'AC',  # section code
                    'perceelnummer': '1234'  # Lot number
                }
            }
        }
    }
)

这个“有点”行得通。我设置了trace=True,因此我得到了大量的日志消息,在这些日志消息中,我看到了一个庞大的xml输出(paste here),它几乎包括了我请求的所有信息。但是,我也得到了回溯:

^{pr2}$

据我所知,这意味着IMKAD_Perceel标记不能被{a4}理解,这是因为它无法在wdsl文件中读取/找到该标记的定义。在

因此,我检查了解析wsdl文件的(大量)日志消息,其中显示了以下几行:

DEBUG:pysimplesoap.helpers:Parsing Element element: IMKAD_Perceel
DEBUG:pysimplesoap.helpers:Processing element IMKAD_Perceel element
DEBUG:pysimplesoap.helpers:IMKAD_Perceel has no children!
DEBUG:pysimplesoap.helpers:complexContent/simpleType/element IMKAD_Perceel = IMKAD_Perceel
DEBUG:pysimplesoap.helpers:Parsing Element complexType: IMKAD_Perceel
DEBUG:pysimplesoap.helpers:Processing element IMKAD_Perceel complexType
DEBUG:pysimplesoap.helpers:complexContent/simpleType/element IMKAD_Perceel = IMKAD_OnroerendeZaak
DEBUG:pysimplesoap.helpers:Processing element IMKAD_Perceel complexType

我想这几行意味着IMKAD_Perceel定义是空的。所以我用SoapUI来反省the WSDL file,在其中我找到了IMKAD_Perceel的定义{a7}:

<xs:element name="IMKAD_Perceel" 
    substitutionGroup="ipkbo:IMKAD_OnroerendeZaak" 
    type="ipkbo:IMKAD_Perceel"
    />

标签看起来确实在关闭,这意味着它是空的。这就是pysimplesoap认为未定义IMKAD_Perceel的原因吗?为什么它不能简单地解释xml并将其作为dict返回呢?(如前所述,我收到的完整xml输出在this paste中)。在

有人知道我如何让pysimplesoap解释xml并将其转换为dict,而不管它是否符合wsdl?在

欢迎所有提示!在


Tags: thedebugclient信息消息定义xmlelement
1条回答
网友
1楼 · 发布于 2024-10-08 18:30:24

似乎pysimplesoap不能处理xmlschema中的substitutionGroup。在

在xsd文件中可以看到:

^{1}$

这里有一个substitutionGroup,这意味着IMKAD_Perceel和{}是同一个东西,可以互相替代。在

在soap模式中,响应的这一特定部分定义为:

^{pr2}$

但是,您可以看到实际的响应是:

<ipkbo:BerichtGegevens>
  <ipkbo:IMKAD_Perceel>...</ipkbo:IMKAD_Perceel>
  <ipkbo:Recht>...</ipkbo:Recht>
  <ipkbo:IMKAD_AangebodenStuk>...</ipkbo:IMKAD_AangebodenStuk>
  <ipkbo:IMKAD_Persoon>...</ipkbo:IMKAD_Persoon>
</ipkbo:BerichtGegevens>

那么pysimplesoap似乎很困惑,无法得到正确的响应类型。在

相关问题 更多 >

    热门问题