python调用WebService遇到的问题'Docume…

2018-08-03 09:29:05来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

代码:

from suds import WebFault
from suds.client import Client 
url = 'http://******/bns/PtDataSvc.asmx?wsdl'
client = Client(url)
print (client)
print(client.service.DoSearch_ByQuery('1002018','Cn','001',"F XX (计算机/TI)"))

错误信息:

Traceback (most recent call last):
  File "D:\新建文件夹\Python练习\dataInterface.py", line 10, in <module>
    print(client.service.DoSearch_ByQuery('1002018','Cn','001',"F XX (计算机/TI)"))
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\client.py", line 576, in invoke
    soapenv = binding.get_message(self.method, args, kwargs)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\bindings\binding.py", line 109, in get_message
    content = self.bodycontent(method, args, kwargs)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\bindings\document.py", line 95, in bodycontent
    add_param, self.options().extraArgumentErrors)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\argparser.py", line 83, in parse_args
    return arg_parser(args, kwargs, extra_parameter_errors)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\argparser.py", line 108, in __call__
    self.__process_parameters()
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\argparser.py", line 299, in __process_parameters
    self.__process_parameter(*pdef)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\argparser.py", line 294, in __process_parameter
    self.__in_choice_context(), value)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\bindings\document.py", line 86, in add_param
    p = self.mkparam(method, pdef, value)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\bindings\document.py", line 130, in mkparam
    return Binding.mkparam(self, method, pdef, object)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\bindings\binding.py", line 225, in mkparam
    return marshaller.process(content)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\mx\core.py", line 59, in process
    self.append(document, content)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\mx\core.py", line 72, in append
    self.appender.append(parent, content)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\mx\appender.py", line 88, in append
    appender.append(parent, content)
  File "C:\Users\ZYKJ\AppData\Local\Programs\Python\Python37\lib\site-packages\suds\mx\appender.py", line 181, in append
    parent.set(attr, value)
AttributeError: 'Document' object has no attribute 'set'

用WebService测试软件测过了接口没有问题,代码也应该没有问题,因为调用另外一个方法是成功的。我把url打码了。考虑到python版本问题我试了python3.6和python3.7都是这个错误。

在网络上目前没有找到这个问题,StackOverflow上有一个和我一样的问题但是0回答......地址在这里:https://stackoverflow.com/questions/47024015/python-suds-attributeerror-document-object-has-no-attribute-set


在pycharm里分别Debug了出错的函数和成功的函数,发现在调用栈的最后一个模块appender.py中的append方法分别执行了if 和else 的语句,就是下面这个函数:

出错的函数就是因为if 判定成功执行到181行时出错。研究了一下为啥if 会判定成功,原来是参数名称被赋给content.tag,而参数名称,如下所见

      (PtDataSvcSoap)
         Methods (9):
            DoSearch(xs:string _strUID, SearchDbType _SDbType, xs:string _strSID, ArrayOfKeyValuePairOfStringString _SearchLis)
            DoSearch_ByQuery(xs:string _strUID, SearchDbType _SDbType, xs:string _strSID, xs:string _strSearchQuery)
            GetCnLegalLst(xs:string _strSID)
            GetCnSimpleLegal(xs:string _strSID)
            GetFmlMemberData(xs:string _strUID, SearchDbType _SDbType, xs:int _nCPIC, xs:int _pageNo, xs:int _pageSize)
            GetGeneralData(xs:string _strUID, SearchDbType _SDbType, xs:string _strSID, xs:int _pageNo, xs:int _pageSize)
            GetPatentData(xs:string _strPID, PatentDataType _PdTpe)
            addUserCount(xs:string ip, xs:int count, xs:string time)
            selectUserSum(xs:string ip, xs:string time)

几乎都有下划线,只有参数名称没有下划线的addUserCount和selectUserSum函数可以用。

于是简单粗暴直接把上面的append函数改成这样了 

试了一下果然好用了。

这么整存在一些隐患,以后可能会有麻烦,但我水平有限,也不懂作者的意图,就先这么着吧。

看了一下stackOverflow上的那位老兄应该也是被这个下划线给整的,谁有账号可以告诉他原因。

错误原因已经找到了,解决办法我给的实在太low,如果哪位大佬有更好的解决办法欢迎交流。

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:经理要我把五百万条数据全部导入Excel!还好有Python!不然等死

下一篇:str中的join方法,fromkeys(),set集合,深浅拷贝(重点)