首页 技术 正文
技术 2022年11月20日
0 收藏 981 点赞 2,254 浏览 4029 个字

代码:

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('','Cn','',"F XX (计算机/TI)"))

错误信息:

Traceback (most recent call last):
File "D:\新建文件夹\Python练习\dataInterface.py", line 10, in <module>
print(client.service.DoSearch_ByQuery('','Cn','',"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 的语句,就是下面这个函数:

python调用WebService遇到的问题'Document' object has no attribute 'set'

出错的函数就是因为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函数改成这样了

python调用WebService遇到的问题'Document' object has no attribute 'set'

试了一下果然好用了。

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

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

错误原因已经找到了,Client包中的函数会把有单前导下划线的参数识别为内部参数,导致报错。这也提醒我们用python时参数命名一定要规范。解决办法我给的实在太low,如果哪位大佬有更好的解决办法欢迎交流。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838