sending a soap request from python

感情迁移 提交于 2019-12-24 02:02:36

问题


I'm trying to send a soap request using the suds python package as below:

from suds.client import Client
WSDL_URL = 'file:/home/Documents/soap/getttt.wsdl'
client = Client(WSDL_URL, cache=None)
result = client.service.GET_TTT(H_ID="01",
                                TTT_ID="44825955",
                                VERSION_DATE="2010-12-01",
                                ACC="B9800B4930543BC4FB305124EDFF7846")
print result

It works fine with a simple wsdl with http uri, but I need to load this wsdl using the file protocol and this wsdl is much more complicated. It imports xsd files like so:

   <types>
      <xsd:schema>
         <xsd:import schemaLocation="GET_TTT.xsd" namespace="http://example.com"/>
         <xsd:import schemaLocation="TTT_TABLES.xsd" namespace="http://example.com"/>
      </xsd:schema>
   </types>

It is failing with this error message:

  File "suds_client.py", line 17, in <module>
    ACC="B9800B4930543BC4FB305124EDFF7846")
  File "python2.7/site-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "python2.7/site-packages/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
  File "python2.7/site-packages/suds/client.py", line 637, in send
    reply = transport.send(request)
  File "python2.7/site-packages/suds/transport/https.py", line 64, in send
    return  HttpTransport.send(self, request)
  File "python2.7/site-packages/suds/transport/http.py", line 77, in send
    fp = self.u2open(u2request)
  File "python2.7/site-packages/suds/transport/http.py", line 118, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>

Any ideas how to debug this? Do I need to use ImportDoctor to load xsd files or does it load them automatically? If I do, then how to load all xsd files? I am able to send the request from that wsdl using a software called soapUI. Thanks


回答1:


If I just use strings as parameters, it complains about the parameter and says

urllib2.URLError: <urlopen error [Errno 111] Connection refused>

Looking at:

<xs:complexType name="T_GET_TTT">
                <xs:attribute name="HES_ID" type="com:hesHesID" use="required"/>
                <xs:attribute name="TTT_ID" type="xs:string" use="required"/>
                <xs:attribute name="VERSION_DATE" type="xs:date" use="required"/>
                <xs:attribute name="ACC" type="xs:hexBinary" use="required"/>
</xs:complexType>

then I decided to use the proper type imported form the xml schema using the doctor:

imp = Import('http://www.w3.org/2001/XMLSchema')
d = ImportDoctor(imp)
imp.filter.add('http://aa')
client = Client(WSDL_URL, cache=None, doctor=d)
print client
client.factory.create('xs:string')

my print command shows that I have the xs:string type: but I get this error:

Exception: prefix (xs) not resolved

Any ideas why it thinks that xs is not a prefix but rather part of the type name?



来源:https://stackoverflow.com/questions/18902517/sending-a-soap-request-from-python

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