Code:
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 (Computer/TI)"))
Error message:
Traceback (most recent call last): File "D:\New folder\Python Practice\dataInterface.py", line 10, in <module> print(client.service.DoSearch_ByQuery('1002018','Cn','001',"F XX (Computer/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'
It's okay to test the interface with WebService, and the code should be okay, because calling another method is successful. I've coded the url. Considering the issue of Python version, I tried both Python 3.6 and python 3.7 to make this mistake.
This problem has not been found on the Internet at present. Stack Overflow has the same question as me, but 0 answers.... The address is here: https://stackoverflow.com/questions/47024015/python-suds-attributeerror-document-object-has-no-attribute-set
In pycharm, the functions that Debug made mistakes and those that succeeded, respectively, find that the append method in appender.py, the last module of the call stack, executes the statements of if and else respectively, which is the following function:
The function that made a mistake was because if determined that it was successfully executed on line 181. We studied why if was successful. It turned out that the parameter name was assigned to content.tag, and the parameter name, as shown below.
(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)
Almost all have underscores, only the addUserCount and selectUserSum functions with no underscores for parameter names can be used.
So simply and roughly change the append function above to something like this.
It worked well after a try.
So there are some hidden dangers, there may be trouble in the future, but my level is limited, and I do not understand the author's intentions, so let's do it first.
Look at the man on stackOverflow who should have been underlined by this line. Who has an account to tell him why?
The reason for the mistake has been found, the solution I give is too low, if any big man has a better solution, welcome to exchange.