我正在尝试使用PySimpleSoap从荷兰政府土地登记处(此处为 WSDL)的 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 输出(在这里粘贴),其中几乎包括我请求的所有信息。但是,我也得到了这个回溯:
Traceback (most recent call last):
File "<input>", line 1, in <module>
'perceelnummer': perceelnummer
File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 181, in <lambda>
return lambda *args, **kwargs: self.wsdl_call(attr, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 346, in wsdl_call
return self.wsdl_call_with_args(method, args, kwargs)
File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 372, in wsdl_call_with_args
resp = response('Body', ns=soap_uri).children().unmarshall(output)
File "/Library/Python/2.7/site-packages/pysimplesoap/simplexml.py", line 433, in unmarshall
value = children and children.unmarshall(fn, strict)
File "/Library/Python/2.7/site-packages/pysimplesoap/simplexml.py", line 433, in unmarshall
value = children and children.unmarshall(fn, strict)
File "/Library/Python/2.7/site-packages/pysimplesoap/simplexml.py", line 433, in unmarshall
value = children and children.unmarshall(fn, strict)
File "/Library/Python/2.7/site-packages/pysimplesoap/simplexml.py", line 380, in unmarshall
raise TypeError("Tag: %s invalid (type not found)" % (name,))
TypeError: Tag: IMKAD_Perceel invalid (type not found)
据我了解,这意味着simplexml 解析器IMKAD_Perceel
无法理解该标签(我猜)是因为它无法在 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来检查WSDL 文件,在其中我找到了这个 .xsd 文件的 url,在其中我找到了以下内容的定义IMKAD_Perceel
:
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
标签确实似乎正在关闭自己,这意味着它是空的。这是pysimplesoap认为IMKAD_Perceel
没有定义的原因吗?为什么它不能简单地解释 xml 并将其作为字典返回?(如前所述,我收到的完整 xml 输出在此粘贴中)。
有谁知道我如何让 pysimplesoap 解释 xml 并将其转换为 dict,不管它是否遵守 wsdl?
欢迎所有提示!