Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SOAP请求中的TypeError(使用PySimpleSAP)_Python_Xml_Soap_Wsdl_Pysimplesoap - Fatal编程技术网

Python SOAP请求中的TypeError(使用PySimpleSAP)

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

我正试图从荷兰政府土地登记处()的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)
我猜这些行意味着
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>