python调用WebService遇到的问题'Document' object has no attribute 'set'
代码:
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'的更多相关文章
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
- Python调用Webservice
使用Python调用webservice 推荐使用 suds包 该包一般在Python2.x python3各种麻烦 略过 实例 import suds # webservice url url ...
- pycharm install python packaging tools时遇到AttributeError: '_NamespacePath' object has no attribute 'sort'错误
pycharm install python packaging tools时报错AttributeError: '_NamespacePath' object has no attribute 's ...
- Python调用Webservice、访问网页
昨天在调试Webservice的时候,由于不想写测试程序,就想用Python访问Webservice,结果还是相当的麻烦.远没有VSIDE用的方便 不得不说VS还是很强大的,人性化做的很好,不需要你看 ...
- python自动化测试,读取excal数据报"'str' object has no attribute 'items'"问题解决
通过python进行自动化测试,为了方便,对代码和数据进行了分离,此处把测试数据放到了excal表格中.requests.post请求时报"'str' object has no attri ...
- python调用webservice接口
使用suds这个第三方模块 from suds.client import Clienturl = 'http://ip:port/?wsdl'cilent=Client(url)print cile ...
- Python的Web编程[2] -> WebService技术[0] -> 利用 Python 调用 WebService 接口
WebService技术 / WebService Technology 1 关于webservice / Constants WebService是一种跨编程语言和跨操作系统平台的远程调用技术. W ...
- python开发笔记-python调用webservice接口
环境描述: 操作系统版本: root@9deba54adab7:/# uname -a Linux 9deba54adab7 --generic #-Ubuntu SMP Thu Dec :: UTC ...
- 【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 ...
随机推荐
- 命令行版扫雷(vc08)
复制代码模拟鼠标各种按键 左键 翻开右键 标雷左右键 翻开周围 先判断当前点是否为已翻开的点 时间地雷计数器清屏 展开 大于8时不管 小于等于8时翻开本身 为0时翻开周围的输出 同雷数图雷区判断 判断 ...
- 关于Windows更新窗口内容的问题(作为一个实验,效果很明显)
Windows中的窗口在特定情况下会由系统进行重绘,如无效区域重新显现时,,会向窗口的处理过程发送VM_PAINT消息,但是,可能还有Windows自己的更新窗口处理,如在下面的代码中,将击键显式地转 ...
- UTM (Urchin Tracking Module) codes
UTM Codes are a great way to see the results of your offline marketing In today’s day and age, we ar ...
- ChannelPipeline----贯穿io事件处理的大动脉
ChannelPipeline贯穿io事件处理的大动脉 上一篇,我们分析了NioEventLoop及其相关类的主干逻辑代码,我们知道netty采用线程封闭的方式来避免多线程之间的资源竞争,最大限度地减 ...
- AWR报告分析案例及命令(收集)
AWR报告分析案例(收集) 循序渐进解读Oracle AWR性能分析报告 AWR报告分析之一:高 DB CPU 消耗的性能根源 生成AWR报告命令: 1)连接数据库:sqlplus / as sysd ...
- js api 之 fetch、querySelector、form、atob及btoa
js api 之 fetch.querySelector.form.atob及btoa 转载请注明出处: https://www.cnblogs.com/funnyzpc/p/11095862.htm ...
- Java NIO: Non-blocking Server 非阻塞网络服务器
本文翻译自 Jakob Jenkov 的 Java NIO: Non-blocking Server ,原文地址:http://tutorials.jenkov.com/java-nio/non-bl ...
- 消息驱动式微服务:Spring Cloud Stream & RabbitMQ
1. 概述 在本文中,我们将向您介绍Spring Cloud Stream,这是一个用于构建消息驱动的微服务应用程序的框架,这些应用程序由一个常见的消息传递代理(如RabbitMQ.Apache Ka ...
- python的列表使用
1.什么是列表 列表是由一系列按特定顺序排列的元素,元素之间可以没有任何关系:可以创建空列表,也可以将任何东西添加进列表. 列表用 [ ] 表示: cars = ['golf', 'magotan', ...
- C# 创建Windows服务demo
一.准备工作 1.操作系统:Windows 10 X64 2.开发环境:VS2017 3.编程语言:C# 4. .NET版本:.NET Framework 4.5 二.创建Windows Servic ...