环境

Windwos 10 1809 x64
Python 3.7.7 x64
pip 20.1
client 0.0.1
suds-jurko 0.6

描述

在执行代码时报错,如下:

Traceback (most recent call last):
  File ".\test.py", line 39, in <module>
    aaa()
  File ".\test.py", line 38, in aaa
    get_org_info(_token, org_id, attrs)
  File ".\test.py", line 21, in get_org_info
    temp = client.service.getOrgInfo(_token, org_id, attrs)
  File "C:\Program Files\Python37\lib\site-packages\suds\client.py", line 521, in __call__
    return client.invoke(args, kwargs)
  File "C:\Program Files\Python37\lib\site-packages\suds\client.py", line 576, in invoke
    soapenv = binding.get_message(self.method, args, kwargs)
  File "C:\Program Files\Python37\lib\site-packages\suds\bindings\binding.py", line 109, in get_message
    content = self.bodycontent(method, args, kwargs)
  File "C:\Program Files\Python37\lib\site-packages\suds\bindings\document.py", line 95, in bodycontent
    add_param, self.options().extraArgumentErrors)
  File "C:\Program Files\Python37\lib\site-packages\suds\argparser.py", line 83, in parse_args
    return arg_parser(args, kwargs, extra_parameter_errors)
  File "C:\Program Files\Python37\lib\site-packages\suds\argparser.py", line 108, in __call__
    self.__process_parameters()
  File "C:\Program Files\Python37\lib\site-packages\suds\argparser.py", line 299, in __process_parameters
    self.__process_parameter(*pdef)
  File "C:\Program Files\Python37\lib\site-packages\suds\argparser.py", line 294, in __process_parameter
    self.__in_choice_context(), value)
  File "C:\Program Files\Python37\lib\site-packages\suds\bindings\document.py", line 86, in add_param
    p = self.mkparam(method, pdef, value)
  File "C:\Program Files\Python37\lib\site-packages\suds\bindings\document.py", line 130, in mkparam
    return Binding.mkparam(self, method, pdef, object)
  File "C:\Program Files\Python37\lib\site-packages\suds\bindings\binding.py", line 225, in mkparam
    return marshaller.process(content)
  File "C:\Program Files\Python37\lib\site-packages\suds\mx\core.py", line 59, in process
    self.append(document, content)
  File "C:\Program Files\Python37\lib\site-packages\suds\mx\core.py", line 72, in append
    self.appender.append(parent, content)
  File "C:\Program Files\Python37\lib\site-packages\suds\mx\appender.py", line 88, in append
    appender.append(parent, content)
  File "C:\Program Files\Python37\lib\site-packages\suds\mx\appender.py", line 298, in append
    parent.set(attr, value)
AttributeError: 'Document' object has no attribute 'set'

根据报错,找到文件 C:Program FilesPython37libsite-packagessudsmxappender.py 第 298 行,发现有以下代码:

if content.tag.startswith('_'):
    attr = content.tag[1:]
    value = tostr(content.value)
    if value:
        parent.set(attr, value)
    else:
        child = self.node(content)
        child.setText(content.value)
        parent.append(child)

发现参数会检测是否下划线开头,若发现下划线开头参数则会执行不应该执行的代码,则会引发报错,将代码注释为如下:

#if content.tag.startswith('_'):
#    attr = content.tag[1:]
#    value = tostr(content.value)
#        if value:
#            parent.set(attr, value)
#    else:
    child = self.node(content)
    child.setText(content.value)
    parent.append(child)
最后修改:2020 年 08 月 24 日 10 : 59 PM
如果觉得文章帮助了您,您可以随意赞赏。