下面是soa接口调用的核心代码
#! /usr/bin/python # coding:utf-8 from suds.client import Clientdef SoaRequest(wsdl,fnname,data): soaService = Client(wsdl).service soaRep = getattr(soaService,fnname)(data) return soaRep
问题就这样出现了:
我调用一个接口,总是报错,见下图:
之后Debug断点定位到suds模块的sxbasic.py文件中的Import类的open方法
def open(self, options):""" Open and import the refrenced schema. @param options: An options dictionary. @type options: L{options.Options} @return: The referenced schema. @rtype: L{Schema} """ if self.opened: return self.opened = True log.debug(‘%s, importing ns="%s", location="%s"‘, self.id, self.ns[1], self.location) result = self.locate() if result is None: if self.location is None: log.debug(‘imported schema (%s) not-found‘, self.ns[1]) else: result = self.download(options) log.debug(‘imported:\n%s‘, result) return result
self.location 为None时日志打印,否则就执行download而我测试的接口有个这种问题,A中依赖B,B中依赖C,C中依赖A,循环依赖所有就出问题了 好吧,那就改吧在类Import外定义数组变量resultList = []
def open(self, options): global resultList#声明全局变量 if self.opened: return self.opened = True log.debug(‘%s, importing ns="%s", location="%s"‘, self.id, self.ns[1], self.location) result = self.locate() if result is None: if self.location is None: log.debug(‘imported schema (%s) not-found‘, self.ns[1]) else: if self.location in resultList: log.debug(‘location is already in resultList‘) #list中存在,即说明已完成下载 else: result = self.download(options) resultList.append(self.location)#下载完成后,往list中添加记录 log.debug(‘imported:\n%s‘, result) return result
这样应该没问题了吧,运行,还是报同样的错
继续调试
。
发现resultList一直是空,就是说下载操作完成后添加记录的操作没有执行
于是我调换了下顺序
直接成功
def open(self, options): global resultList if self.opened: return self.opened = True log.debug(‘%s, importing ns="%s", location="%s"‘, self.id, self.ns[1], self.location) result = self.locate() if result is None: if self.location is None: log.debug(‘imported schema (%s) not-found‘, self.ns[1]) else: if self.location in resultList: log.debug(‘location is already in resultList‘) else: resultList.append(self.location) result = self.download(options) log.debug(‘imported:\n%s‘, result) return result
时间: 2024-11-08 23:55:24