相关文章推荐
捣蛋的路灯  ·  Dire Straits ...·  3 月前    · 
俊逸的青蛙  ·  西山居游戏·  1 年前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When you pass a wsse as a list to the client, like this:
client = Client(wsdl=url, transport=transport, wsse=[self.user_name_token])
client = Client(wsdl=url, transport=transport, wsse=[self.user_name_token, self.signature])

You get an error in the process_reply, like this:
response = client.service.RIDP(**input)
File "/Users/cathleenturner/.local/share/virtualenvs/services-m78ruPbe/lib/python3.7/site-packages/zeep/proxy.py", line 42, in call
self._op_name, args, kwargs)
File "/Users/cathleenturner/.local/share/virtualenvs/services-m78ruPbe/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", line 132, in send
return self.process_reply(client, operation_obj, response)
File "/Users/cathleenturner/.local/share/virtualenvs/services-m78ruPbe/lib/python3.7/site-packages/zeep/wsdl/bindings/soap.py", line 184, in process_reply
client.wsse.verify(doc)
AttributeError: 'list' object has no attribute 'verify'

The examples refer to passing in wsse as a list.

https://python-zeep.readthedocs.io/en/master/wsse.html

>>> from zeep import Client
>>> from zeep.wsse.username import UsernameToken
>>> from zeep.wsse.signature import Signature
>>> user_name_token = UsernameToken('username', 'password')
>>> signature = Signature(private_key_filename, public_key_filename,
...     optional_password)
>>> client = Client(
...     'http://www.webservicex.net/ConvertSpeed.asmx?WSDL',
...     wsse=[user_name_token, signature])

The workaround is to not pass it as a list, like so:
client = Client(wsdl=url, transport=transport, wsse=self.user_name_token)

Would be good to get a heads up on this error in the docs before entering a rabbit hole.

I'm also trying to connect to a service that requires both token and signature verifications. The workaround from OP does not work in that case.

See my pull request #1077 for a fix.

Fixes #953 - AttributeError: 'list' object has no attribute 'verify' when you pass in list wsse #1077

While it gets fixed properly, here was my workaround:

class CustomSignature(object):
    """Sign given SOAP envelope with WSSE sig using given key and cert."""
    def __init__(self, wsse_list):
        self.wsse_list = wsse_list
    def apply(self, envelope, headers):
        for wsse in self.wsse_list:
            envelope, headers = wsse.apply(envelope, headers)
        return envelope, headers
    def verify(self, envelope):

To use it:

user_name_token = UsernameToken(user, password)
signature = Signature(private_key, signed_cert, certificate_password)
client = Client(soap_endpoint, wsse=CustomSignature([user_name_token, signature]))
      x509 Feat and Fix - fixes multiple wsse, add option do disable response verification, and use another cert  for verify
      #1429