Python SOAP请求中的TypeError(使用PySimpleSAP)
我正试图从荷兰政府土地登记处()的SOAP服务中获取相关信息。到目前为止,我使用以下代码连接并请求有关特定属性的信息:Python SOAP请求中的TypeError(使用PySimpleSAP),python,xml,soap,wsdl,pysimplesoap,Python,Xml,Soap,Wsdl,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', tra
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)
我猜这些行意味着IMKAD_Perceel
定义是空的。所以我习惯于内省,在内省中,我找到了IMKAD_Perceel
的定义:
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
标签看起来确实在自动关闭,这意味着它是空的。这就是pysimplesoap认为未定义IMKAD_Perceel
的原因吗?为什么它不能简单地解释xml并将其作为dict返回?(如前所述,我收到的完整xml输出在中)
有人知道我如何让pysimplesoap解释xml并将其转换为dict,而不管它是否遵循wsdl吗
欢迎所有提示 似乎
pysimplesoap
无法处理xml模式中的substitutionGroup
您可以在xsd文件中看到:
<xs:element name="IMKAD_Perceel"
substitutionGroup="ipkbo:IMKAD_OnroerendeZaak"
type="ipkbo:IMKAD_Perceel"
/>
但是,您可以看到实际响应如下所示:
<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
似乎会感到困惑,无法获得正确的响应类型。我们无法重现错误,因为我们无权使用此服务。我认为您最好与此web服务的提供商联系。@skyline75489-我添加了一个我收到的xml的粘贴:。这有助于调试吗?您得到的响应似乎没有问题,即使它抱怨类型错误
。回答有问题吗?@skyline75489-回答很好。只是我不能对响应做任何事情,因为pysimplesoap给出了这个错误。你知道我如何解决这个错误吗?我想问题出在simplexml实现的某个地方。出错的行是:。我尝试将strict
设置为False
,但是IMKAD\u Perceel
变成。\n\n\n\n\n\n\n\n\n\n\n'
我无法对响应做任何事情,具体做什么会导致此错误?感谢您对错误来源的彻底分析和解释。你可能也知道我怎么才能解决这个问题吗?simplexml的源包含在pysimplesource()中。你知道我如何编辑它以使substitutionGroup
s工作吗?你可以尝试使用types['IMKAD\u Perceel']=types['IMKAD\u OnroerendeZaak']
对其进行黑客攻击。只需将此添加到它开头的unmarshall
函数中。如果我尝试这样做,我会得到一个关键错误:文件“pysimplesoap/simplexml.py”,第325行,在unmarshall types['IMKAD_Perceel']=types['IMKAD_onroerendzak']键错误:u'IMKAD_onroerendzak'
IMKAD_OnroerendeZaak
被认为也没有加载到类型中。还有别的主意吗?你不能这么做。因为此函数是为每个SimpleXMLElement调用的。我建议在类型中添加if'IMKAD_OnroerendeZaak
,因为这会导致许多内容无法呈现,所以我决定只将原始xml作为字符串返回,并使用它进行转换,然后进一步清理。虽然不漂亮,但现在还可以用。非常感谢你帮助我了解更多!
<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>