Python 如何用pysimplesoap构造SOAP消息?
我正在尝试调用来自荷兰政府土地登记处()的SOAP服务。到目前为止,我这样做是为了连接:Python 如何用pysimplesoap构造SOAP消息?,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') 在的帮助下,我现在明白了我需要使用client.VerzoekTotInformatie()方法发
from pysimplesoap.client import SoapClient
client = SoapClient(wsdl='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl')
在的帮助下,我现在明白了我需要使用client.VerzoekTotInformatie()
方法发送下面的xml
然而,我不明白的是如何获得所需的XML(见下文)。我当然可以手动构建它,但我觉得有一种更聪明/更具python风格的方法来构建它。我可以使用pysimplesoap来构造这个消息xml吗
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.kadaster.nl/schemas/kik-inzage/20141101" xmlns:v20="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">
<soapenv:Header/>
<soapenv:Body>
<ns:VerzoekTotInformatieRequest>
<v20:Aanvraag>
<v20:berichtversie>?</v20:berichtversie>
<v20:klantReferentie>ABC</v20:klantReferentie>
<v20:productAanduiding>?</v20:productAanduiding>
<v20:Ingang>
<v20:Object>
<v20:IMKAD_KadastraleAanduiding>
<v20:gemeente>Amsterdam</v20:gemeente>
<v20:sectie>123</v20:sectie>
<v20:perceelnummer>456</v20:perceelnummer>
<v20:appartementsindex>789</v20:appartementsindex>
<v20:deelperceelnummer>10</v20:deelperceelnummer>
<v20:AKRKadastraleGemeenteCode>20</v20:AKRKadastraleGemeenteCode>
</v20:IMKAD_KadastraleAanduiding>
</v20:Object>
</v20:Ingang>
</v20:Aanvraag>
</ns:VerzoekTotInformatieRequest>
</soapenv:Body>
</soapenv:Envelope>
构造xml不是调用soap方法的必要(或正确)方法
PySimpleSoap
已经提供了一种非常优雅且易于阅读的方法:
client = SoapClient(wsdl='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl', trace=True)
client.VerzoekTotInformatie(Aanvraag={'berichtversie':4.7,
'klantReferentie':'cum murmure',
'productAanduiding': 'aeoliam venit'})
调试日志如下所示:
INFO:pysimplesoap.client:POST https://service1.kadaster.nl/kik/inzage/20141101/VerzoekTotInformatieService
DEBUG:pysimplesoap.client:SOAPAction: "VerzoekTotInformatie"
Content-length: 842
Content-type: text/xml; charset="UTF-8"
DEBUG:pysimplesoap.client:<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header/>
<soap:Body>
<VerzoekTotInformatieRequest xmlns="http://www.kadaster.nl/schemas/kik-inzage/20141101">
<Aanvraag xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">
<berichtversie xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">4.7000000000</berichtversie>
<klantReferentie xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">cum murmure</klantReferentie>
<productAanduiding xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">aeoliam venit</productAanduiding>
</Aanvraag>
</VerzoekTotInformatieRequest>
</soap:Body>
</soap:Envelope>
INFO:pysimplesoap.client:POSThttps://service1.kadaster.nl/kik/inzage/20141101/VerzoekTotInformatieService
调试:pysimplesoap.client:SOAPAction:“VerzoekTotInformatie”
内容长度:842
内容类型:text/xml;charset=“UTF-8”
调试:pysimplesoap.client:
4.7000000000
耳鸣
风叶鹿肉
如您所见,xml会自动构造并发送到服务器。但是我得到了
401:Unauthorized
错误,您可能知道如何修复该错误。中对此进行了解释。查看页面和示例。@abarnert-我查看了这些文档,据我所知,我需要使用SimpleXMLElement创建xml。但是,我是否也可以使用VerzoektoInformatieRequest
的原始定义以某种方式构建并仅填充缺失的细节?使用SimpleXMLElement创建整个XML的示例中,只有最后一个是“原始示例”,您仅在需要时使用它“-Raw full control-(手动序列化参数和对返回值进行序列化)”。如果不需要,请不要使用该示例。@abarnert-Ah,现在我明白了,谢谢!最后一个问题:如何显示/检查客户端构造的xml。例如,我现在做了client['VerzoekTotInformatieRequest']={'berichtVersione':'lala'}
。我如何检查这对它生成的xml有何影响?谢谢!我不知道我可以简单地使用字典在xml中创建对象。我确实知道如何修复401;您需要为服务付费…-)。万分感谢!我会在20分钟内奖励你+100。你好@skyline75489。在您就我的问题向我提供了极好的帮助之后,我现在面临一个问题,返回的xml在PySimpleSAP中创建了一个TypeError(TypeError:Tag:IMKAD_Perceel invalid(找不到类型)
)。我在这里提出了一个新问题:。您可能知道如何修复该类型错误吗?
INFO:pysimplesoap.client:POST https://service1.kadaster.nl/kik/inzage/20141101/VerzoekTotInformatieService
DEBUG:pysimplesoap.client:SOAPAction: "VerzoekTotInformatie"
Content-length: 842
Content-type: text/xml; charset="UTF-8"
DEBUG:pysimplesoap.client:<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header/>
<soap:Body>
<VerzoekTotInformatieRequest xmlns="http://www.kadaster.nl/schemas/kik-inzage/20141101">
<Aanvraag xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">
<berichtversie xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">4.7000000000</berichtversie>
<klantReferentie xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">cum murmure</klantReferentie>
<productAanduiding xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">aeoliam venit</productAanduiding>
</Aanvraag>
</VerzoekTotInformatieRequest>
</soap:Body>
</soap:Envelope>