python-zeep icon indicating copy to clipboard operation
python-zeep copied to clipboard

AttributeError: 'list' object has no attribute 'verify' when you pass in list wsse

Open cat-turner opened this issue 6 years ago • 9 comments

When you pass a wsse as a list to the client, like this: client = Client(wsdl=url, transport=transport, wsse=[self.user_name_token]) or 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.

cat-turner avatar Apr 23 '19 19:04 cat-turner

We have to give both, UsernameToken and BinarySecurityToken, hence: +1

erny avatar Jun 03 '19 14:06 erny

+1 Is there any workaround to give username and signature to the wsse?

JessCasasDev avatar Sep 11 '19 16:09 JessCasasDev

+1 any progress in this issue?

jlariza avatar Mar 18 '20 12:03 jlariza

+1 any progress in this issue?

For now, the workaround is to not pass it as a list. It worked for me.

n00blet avatar Mar 18 '20 12:03 n00blet

@n00blet the issue is that the service I am consuming requires both token and signature verifications; so I need to pass them as a list.

jlariza avatar Mar 18 '20 12:03 jlariza

+1 any progress in this issue? Or any workaround?

gabrielfarah avatar Mar 28 '20 04:03 gabrielfarah

+1 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.

epetrovski avatar Apr 22 '20 15:04 epetrovski

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):
        pass

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]))

gabrielfarah avatar May 08 '20 23:05 gabrielfarah

Thanks @gabrielfarah you are amazing... You made my day so warn... love u...

DaggerAlmanza avatar Sep 18 '21 15:09 DaggerAlmanza