我正在尝试使用zeep创建一个python soap客户端,但在尝试访问wsdl时遇到了一些问题。无论我尝试过多少网上现有的解决方案,它们都不再有用,或者只是我的情况有点不同。最有希望的是官方zeep文档中的解决方案,但它仍然不太有效:
from requests import Session
from requests.auth import HTTPBasicAuth # or HTTPDigestAuth, or OAuth1, etc.
from zeep import Client
from zeep.transports import Transport
session = Session()
session.auth = HTTPBasicAuth(user, password)
client = Client('https://url/to/my_wsdl.wsdl',
transport=Transport(session=session))
但是我收到了一个错误:
File "C:\Python36-32\lib\site-packages\zeep\client.py", line 124, in __init__
self.wsdl = Document(wsdl, self.transport, strict=strict)
File "C:\Python36-32\lib\site-packages\zeep\wsdl\wsdl.py", line 82, in __init__
root_definitions.resolve_imports()
File "C:\Python36-32\lib\site-packages\zeep\wsdl\wsdl.py", line 234, in resolve_imports
binding.resolve(self)
File "C:\Python36-32\lib\site-packages\zeep\wsdl\definitions.py", line 128, in resolve
operation.resolve(definitions)
File "C:\Python36-32\lib\site-packages\zeep\wsdl\bindings\soap.py", line 428, in resolve
self.output.resolve(definitions, self.abstract.output_message)
File "C:\Python36-32\lib\site-packages\zeep\wsdl\messages\soap.py", line 285, in resolve
self.body = self._resolve_body(info['body'], definitions, parts)
File "C:\Python36-32\lib\site-packages\zeep\wsdl\messages\soap.py", line 423, in _resolve_body
element = part.element.clone()
AttributeError: 'NoneType' object has no attribute 'clone'
我错过了什么或做错了什么?我在Windows 10上使用python3.6 32位。所有软件包都是使用pip新安装的。
答案 0 :(得分:1)
这里的作者。好像你在Zeep中遇到了一个bug。您能否按照http://docs.python-zeep.org/en/master/reporting_bugs.html至https://github.com/mvantellingen/python-zeep/issues的说明提交问题?
我会尽快看看它。
答案 1 :(得分:0)
显然现在没有解决这个问题的办法。也许在将来的Zeep版本中,这个bug将被修复。
但是我找到了解决方法。而不是Zeep使用SUDS(或python3.x的suds-py3)。使用用户和密码要求从wsdl创建客户端在这里更简单。只需使用:
from suds.client import Client
client = Client(url=WSDL_URL,
username=WSDL_USERNAME,
password=WSDL_PASSWORD)