我正在尝试使用PySimpleSoap从荷兰政府土地登记册(WSDL)获取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 …
Run Code Online (Sandbox Code Playgroud) 我在 Python 3 中有一个带有 pysimplesoap 的 SOAP 服务器。
代码
from wsgiref.simple_server import make_server
application = WSGISOAPHandler(dispatcher)
wsgid = make_server('', 8008, application)
wsgid.serve_forever()
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会出现以下错误。
错误
Traceback (most recent call last):
File "/usr/lib/python3.4/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
self.write(data)
File "/usr/lib/python3.4/wsgiref/handlers.py", line 266, in write
"write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance
Run Code Online (Sandbox Code Playgroud) 第一次使用 SOAP 并想知道如何使用 django 发出简单的 SOAP 请求?我还没有尝试设置 pysimplesoap,我首先只想连接到网络服务。
我有一个 XML 标头和正文的字符串
xml_header = ""
xml_body = ""
Run Code Online (Sandbox Code Playgroud)
如何发送此请求并等待响应?
编辑:我使用 Python 3.4 for SUDS 不是一个选项
我正在尝试使用PySimpleSoap从荷兰政府土地登记处(WSDL)调用SOAP服务.到目前为止,我这样做是为了连接:
from pysimplesoap.client import SoapClient
client = SoapClient(wsdl='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl')
Run Code Online (Sandbox Code Playgroud)
在Plamen Petrov的一个很棒的答案的帮助下,我现在明白我需要使用这个client.VerzoekTotInformatie()
方法发送下面的xml .
然而,我不明白的是我如何获得所需的XML(见下文).我当然可以手动构建它,但我感觉有一种更聪明/更pythonic的方式来构建它.我可以使用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>
Run Code Online (Sandbox Code Playgroud)
[编辑]
按照文档中的示例,我现在尝试berichtversie
在其中添加VerzoekTotInformatieRequest ,之后我尝试向soap-service请求.但正如你在下面看到的那样,身体仍然只有空<VerzoekTotInformatie>
(没有Request
),而且我得到了一个巨大的错误.我有什么想法可以构建上面的消息?
>>> client['VerzoekTotInformatieRequest'] = {'Aanvraag': {'berichtversie': 'yay'}}
>>> c.VerzoekTotInformatie()
INFO:pysimplesoap.client:POST https://service1.kadaster.nl/kik/inzage/20141101/VerzoekTotInformatieService
DEBUG:pysimplesoap.client:SOAPAction: "VerzoekTotInformatie"
Content-length: 378
Content-type: text/xml; charset="UTF-8"
DEBUG:pysimplesoap.client:<?xml …
Run Code Online (Sandbox Code Playgroud)