SUDS Python 连接
我正在用Python和suds构建一个网络服务的客户端。我参考了这个网站上的教程:http://www.jansipke.nl/python-soap-client-with-suds。这个教程在我自己写的网络服务和WSDL文件上运行得很好,但在我得到的WSDL文件上却不行。这个WSDL文件在soapUI中可以正常工作,我可以发送请求并得到回复。所以我觉得问题可能出在suds解析WSDL文件的方式上。我遇到了以下错误:
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>
有没有什么办法可以解决这个问题?如果你需要更多信息,请问我。谢谢!
2 个回答
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))
当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的语言解释清楚。
3
你给我们的错误信息看起来是说,你用来访问WSDL的链接不对。能不能多给我们看看你的代码?比如说客户端是怎么创建的,还有WSDL的链接是什么。这样可能会让其他人更好地帮助你。
Olly