How to construct SOAP message with pysimplesoap?

巧了我就是萌 提交于 2019-12-03 04:02:58

Constructing xml is not the necessary (or correct) way to call a soap method. PySimpleSoap has already provided quite an elegant and human-readable way to do this:

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'})

The debug log would be like this:

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>

As you can see, the xml is automatically constructed and sent to server. However I got 401: Unauthorized error, which you may know how to fix.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!