代码:

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 的语句,就是下面这个函数:

出错的函数就是因为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上的那位老兄应该也是被这个下划线给整的,谁有账号可以告诉他原因。

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

python调用WebService遇到的问题'Document' object has no attribute 'set'的更多相关文章

  1. Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'

    使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...

  2. Python调用Webservice

    使用Python调用webservice 推荐使用 suds包 该包一般在Python2.x   python3各种麻烦 略过 实例 import suds # webservice url url ...

  3. pycharm install python packaging tools时遇到AttributeError: '_NamespacePath' object has no attribute 'sort'错误

    pycharm install python packaging tools时报错AttributeError: '_NamespacePath' object has no attribute 's ...

  4. Python调用Webservice、访问网页

    昨天在调试Webservice的时候,由于不想写测试程序,就想用Python访问Webservice,结果还是相当的麻烦.远没有VSIDE用的方便 不得不说VS还是很强大的,人性化做的很好,不需要你看 ...

  5. python自动化测试,读取excal数据报"'str' object has no attribute 'items'"问题解决

    通过python进行自动化测试,为了方便,对代码和数据进行了分离,此处把测试数据放到了excal表格中.requests.post请求时报"'str' object has no attri ...

  6. python调用webservice接口

    使用suds这个第三方模块 from suds.client import Clienturl = 'http://ip:port/?wsdl'cilent=Client(url)print cile ...

  7. Python的Web编程[2] -> WebService技术[0] -> 利用 Python 调用 WebService 接口

    WebService技术 / WebService Technology 1 关于webservice / Constants WebService是一种跨编程语言和跨操作系统平台的远程调用技术. W ...

  8. python开发笔记-python调用webservice接口

    环境描述: 操作系统版本: root@9deba54adab7:/# uname -a Linux 9deba54adab7 --generic #-Ubuntu SMP Thu Dec :: UTC ...

  9. 【python问题系列--3】TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

    p0V,p1V,pSpam=trainNBO(array[trainMat],array(trainClasses)) 改为: p0V,p1V,pSpam=trainNBO(array(trainMa ...

随机推荐

  1. 虚拟机安装 ubuntu 后,更新源无效,以及无法联网安装软件的问题

    问题: 虚拟机安装 ubuntu 后,更新源无效,以及无法联网安装软件: 错误提示: Err http://security.ubuntu.com/ubuntu/ trusty-security/un ...

  2. DataVeryLite入门教程(一) 配置篇

    DataVeryLite 是基于.net 4.0的数据库持久化ORM框架. 目前支持的数据库有Sqlserver,Mysql,Oracle,Db2,PostgreSql,Sqlite和Access. ...

  3. java关键字之synchronized

    1.synchronized可以用了修饰一个普通方法,或者代码块,这个时候synchronized锁定的是当前对象,只要有一个线程在访问对应的方法或代码块,其他线程必须等待.2.synchronize ...

  4. Python Re 模块超全解读!

    re模块下的函数 compile(pattern):创建模式对象 import repat=re.compile('A')m=pat.search('CBA')                     ...

  5. Scala 学习之路(八)—— 类和对象

    一.初识类和对象 Scala的类与Java的类具有非常多的相似性,示例如下: // 1. 在scala中,类不需要用public声明,所有的类都具有公共的可见性 class Person { // 2 ...

  6. Docker配置容器位置和小技巧

    Docker使用小技巧 清理全部停止的docker容器 有时候我们会有很多已经停止的容器或者由于错误强制退出不能用的容器,那我们就需要删除了,但是我们一个一个的rm删除很麻烦,有多少容器就要rm多少次 ...

  7. Github项目备份与更新

    需求 假如现在想对使用到的一些Github上的开源组件进行备份,采用自建Gitlab服务器的方式进行备份保存,并且组件需定时保持与Github更新. 总体步骤 组件备份- 整体步骤如下: a.搭建gi ...

  8. 为什么现在这么多人开始学习Python?

    近几年Python编程语言在国内引起不小的轰动,有超越JAVA之势,本来在美国这个编程语言就是最火的,应用的非常非常的广泛,而Python的整体语言难度来讲又比JAVA简单的很多.尤其在运维的应用中非 ...

  9. SwiftLint:代码规范检查工具介绍

    Swift-CodeStyle Checker:SwiftLint 介绍: SwiftLint 是一个用于强制检查 Swift 代码风格和规定的一个工具,基本上以 GitHub's Swift 代码风 ...

  10. Python中的字符编码

    一.文本编辑器存取文件的原理: #1.打开编辑器就打开了启动了一个进程,是在内存中的,所以,用编辑器编写的内容也都是存放与内存中的,断电后数据丢失 #2.要想永久保存,需要点击保存按钮:编辑器把内存的 ...