SOAP 请求中的类型错误(使用 pysimplesoap)
TypeError in SOAP Request (using pysimplesoap)
我正在尝试从荷兰政府土地登记处的 SOAP 服务中获取相关信息(WSDL here) with PySimpleSoap。到目前为止,我设法通过以下方式连接并请求有关特定 属性 的信息代码:
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
}
}
}
}
)
这个"kinda"有效。我设置了 trace=True
所以我得到了大量的日志消息,在这些日志消息中我看到了一个巨大的 xml 输出(paste here),它几乎包括了我请求的所有信息。但是,我也得到了这个回溯:
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 parser 无法理解 IMKAD_Perceel
标签,这(我猜)是因为它无法 read/find 定义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 to introspect the WSDL file, in which I found an url to this .xsd-file 在其中找到 IMKAD_Perceel
:
的定义
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
标签确实似乎正在自行关闭,这意味着它是空的。这是 pysimplesoap 认为 IMKAD_Perceel
未定义的原因吗?为什么它不能简单地将 xml 和 return 解释回字典? (如前所述,我收到的完整 xml 输出在 this paste 中)。
有谁知道我如何让 pysimplesoap 解释 xml 并将其转换为字典,无论它是否遵守 wsdl?
欢迎所有提示!
似乎 pysimplesoap
无法处理 xml 架构中的 substitutionGroup
。
您可以在 xsd 文件中看到:
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
还有这个substitutionGroup
,也就是说IMKAD_Perceel
和IMKAD_OnroerendeZaak
是同一个东西,可以互相替代。
在 soap 模式中,响应的这个特定部分定义为:
<xs:complexType name="BerichtGegevens">
<xs:annotation>
<xs:documentation>Inhoud van het bericht.</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element ref="ipkbo:IMKAD_OnroerendeZaak" minOccurs="1" maxOccurs="1"/>
<xs:element ref="ipkbo:Recht" minOccurs="1" maxOccurs="1"/><xs:element ref="ipkbo:IMKAD_Stuk" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="ipkbo:IMKAD_Persoon" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="ipkbo:GemeentelijkeRegistratie" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
但是,您可以看到实际响应如下:
<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
似乎感到困惑,无法获得正确的响应类型。
我正在尝试从荷兰政府土地登记处的 SOAP 服务中获取相关信息(WSDL here) with PySimpleSoap。到目前为止,我设法通过以下方式连接并请求有关特定 属性 的信息代码:
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
}
}
}
}
)
这个"kinda"有效。我设置了 trace=True
所以我得到了大量的日志消息,在这些日志消息中我看到了一个巨大的 xml 输出(paste here),它几乎包括了我请求的所有信息。但是,我也得到了这个回溯:
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 parser 无法理解 IMKAD_Perceel
标签,这(我猜)是因为它无法 read/find 定义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 to introspect the WSDL file, in which I found an url to this .xsd-file 在其中找到 IMKAD_Perceel
:
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
标签确实似乎正在自行关闭,这意味着它是空的。这是 pysimplesoap 认为 IMKAD_Perceel
未定义的原因吗?为什么它不能简单地将 xml 和 return 解释回字典? (如前所述,我收到的完整 xml 输出在 this paste 中)。
有谁知道我如何让 pysimplesoap 解释 xml 并将其转换为字典,无论它是否遵守 wsdl?
欢迎所有提示!
似乎 pysimplesoap
无法处理 xml 架构中的 substitutionGroup
。
您可以在 xsd 文件中看到:
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
还有这个substitutionGroup
,也就是说IMKAD_Perceel
和IMKAD_OnroerendeZaak
是同一个东西,可以互相替代。
在 soap 模式中,响应的这个特定部分定义为:
<xs:complexType name="BerichtGegevens">
<xs:annotation>
<xs:documentation>Inhoud van het bericht.</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element ref="ipkbo:IMKAD_OnroerendeZaak" minOccurs="1" maxOccurs="1"/>
<xs:element ref="ipkbo:Recht" minOccurs="1" maxOccurs="1"/><xs:element ref="ipkbo:IMKAD_Stuk" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="ipkbo:IMKAD_Persoon" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="ipkbo:GemeentelijkeRegistratie" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
但是,您可以看到实际响应如下:
<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
似乎感到困惑,无法获得正确的响应类型。