我正在尝试使用suds在python中为web服务构建一个客户端。我用过这个教程 在此网站上:http://www.jansipke.nl/python-soap-client-with-suds。它使用我自己编写的Web服务和WSDL,但没有使用我得到的wsdl文件。 wsdl文件在soapUI中工作,我可以发送请求并得到答案。所以问题是,我认为,suds是如何解析wsdl文件的。我收到以下错误:
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>
任何想法如何解决?如果您需要更多信息,请询问。谢谢!
答案 0 :(得分:3)
您给我们的错误似乎暗示您用于访问WSDL的URL不正确。你能告诉我们你的代码吗?例如客户端instatiation和WSDL的url。这可能会让其他人真正帮助你。
奥利
答案 1 :(得分:1)
# SUDS is primarily built for Python 2.6/7 (Lightweight SOAP client)
# SUDS does not work properly with other version, absolutely no support for 3.x
# Test your code with Python 2.7.12 (I am using)
from suds.client import Client
from suds.sax.text import Raw
# Use your tested URL same format with '?wsdl', Check once in SOAP-UI, below is dummy
# Make sure to use same Method name in below function 'client.service.MethodName'
url = 'http://localhost:8080/your/path/MethodName?wsdl'
#Use your Request XML, below is dummy, format xml=Raw('xml_text')
xml = Raw('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:diag=" </soapenv:Body></soapenv:Envelope>')
def GetResCode(url, xml):
client = Client(url)
xml_response = (client.service.MethodName(__inject={'msg':xml}))
return xml_response
print(GetResCode(url,xml))