我对python很陌生,在使用SUDS包调用SOAP方法时遇到了一些问题。我有这个Tk应用程序,在Treeview小部件中,我从条目小部件中选择方法名称和传递参数值。我可以在变量中获得方法名,但问题是,如何将变量值作为SUDS方法名传递?
我有这样的代码:
from tkinter import *
from tkinter import ttk
import sys
from suds.client import *
class SoapClass:
def __init__(self, master):
self.client = Client('http://www.webservicex.net/ConvertWeight.asmx?WSDL', username='', password='', faults=False)
Button(master, text='Call', command=self.request).pack()
def request(self):
methodName = 'ConvertWeight'
#Here I would like to pass methodName variable
response = self.client.service.ConvertWeight(80, 'Kilograms', 'Grams')
print(response)
root = Tk()
app = SoapClass(root)
root.mainloop()我想这样做:
methodName = 'ConvertWeight'
response = self.client.service.methodName(80, 'Kilograms', 'Grams')当然,Web服务给了我:
raise (Qn)
found:'ConvertWeights.ConvertWeightsSoap.methodName':suds.MethodNotFound:方法而不是suds.MethodNotFound
我该怎么做?这有可能吗?
发布于 2015-12-04 09:19:23
在上网一段时间后,我找到了解决办法。
一开始我查到了这个:
params = client.factory.create('ConvertWeight')而不是向这个对象添加所需的参数。
不幸的是,由于我调查过,我的WSDL被破坏了,但是ImportDoctor无法修复我的WSDL,在调用client.factory.create()时,错误地说"Type“,这清楚地表明了WSDL的某些地方不对。
不管怎样,我找到了另一个解决办法:
MethodToExecute = getattr(self.client.service, methodName)
try:
response = MethodToExecute(*array)
except WebFault as e:
response = e因此,现在我可以调用我选择的任何方法,并添加任意多的参数。
希望我的解决方案能帮上忙。
https://stackoverflow.com/questions/34061861
复制相似问题