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

AttributeError: 'BinarySignature' object has no attribute 'egress'

Open Lamasape opened this issue 4 years ago • 3 comments

Hi!!

zeep version 4.1.0

I am trying to add security headers exactly BinarySecurityToken and to be able to sign the headers of the worst adressing when using the BinarySignature plugin I get the following error: AttributeError: 'BinarySignature' object has no attribute 'egress'

This is the code I'm using:

`
   import shutil


from requests import Session
from zeep import Client, Settings, Transport, wsse
from OpenSSL import crypto
from zeep.wsa import WsAddressingPlugin
from lxml.builder import ElementMaker
import logging.config

from datetime import date
from pathlib import Path

from zeep.wsse import Signature, BinarySignature

from transport_with_attach import TransportWithAttach

logging.config.dictConfig({
    'version': 1,
    'formatters': {
        'verbose': {
            'format': '%(name)s: %(message)s'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'zeep.transports': {
            'level': 'DEBUG',
            'propagate': True,
            'handlers': ['console'],
        },
    }
})

wsdl_url = 'xxxxxxxxxxxxxxxxxxxxx'


def load_certificates_in_session():
    p12 = crypto.load_pkcs12(open("../XXX.p12", 'rb').read(), b"xxxxx")
    cert = crypto.dump_certificate(crypto.FILETYPE_PEM, p12.get_certificate())
    key = crypto.dump_privatekey(crypto.FILETYPE_PEM, p12.get_privatekey())

    with open('cert.pem', 'wb') as f:
        f.write(cert)
    with open('key.pem', 'wb') as f:
        f.write(key)

    session = Session()
    session.cert = ('./cert.pem', './key.pem')

    return session


def get_wsa_headers():
    wsa = ElementMaker(namespace='http://www.w3.org/2005/08/addressing')
    return [
        wsa.ReplyTo(wsa.Address('http://www.w3.org/2005/08/addressing/anonymous')),
    ]


def configure_client():
    session = load_certificates_in_session()
    settings = Settings(strict=False, xml_huge_tree=True)
    transport = Transport(session=session)

    return Client(
        wsdl_url,
        wsse=Signature(key_file='key.pem', certfile='cert.pem', password=None),
        transport=transport,
        service_name='ConsultaService',
        plugins=[WsAddressingPlugin(), wsse.BinarySignature(key_file='key.pem', certfile='cert.pem', password=None)
                 ],
        settings=settings,
    )


def configure_service_proxy(client):
    return client.create_service(
        '{XXXXXX,
        'XXXXXXX'
    )


def consulta():
    client = configure_client()
    service = configure_service_proxy(client)

    response = service.Consulta(_value_1=[{'ids': '1234'}, {'ids': '2225'}],
                                        _soapheaders=get_wsa_headers())

    print(response)



if __name__ == '__main__':
    consulta()

` I get this error:

Traceback (most recent call last):
  File "C:\Users\xxx\PycharmProjects\consulta\src\main.py", line 148, in <module>
    consulta()
  File "C:\Users\xxx\PycharmProjects\consulta\src\main.py", line 97, in consulta
    response = service.Consulta(_value_1=[{'ids': '1234'}, {'ids': '2225'}],
  File "C:\Users\xxx\PycharmProjects\consulta\venv\lib\site-packages\zeep\proxy.py", line 46, in __call__
    return self._proxy._binding.send(
  File "C:\Users\xxx\PycharmProjects\consulta\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 123, in send
    envelope, http_headers = self._create(
  File "C:\Users\xxx\PycharmProjects\consulta\venv\lib\site-packages\zeep\wsdl\bindings\soap.py", line 90, in _create
    envelope, http_headers = plugins.apply_egress(
  File "C:\Users\xxx\PycharmProjects\consulta\venv\lib\site-packages\zeep\plugins.py", line 33, in apply_egress
    result = plugin.egress(envelope, http_headers, operation, binding_options)
AttributeError: 'BinarySignature' object has no attribute 'egress'

I can't even create a request.

Thanks very much for any info!

Lamasape avatar Sep 28 '21 14:09 Lamasape

Hi! Can you resolve this issue with the BinarySignature?

MeryGimenez avatar Feb 02 '22 19:02 MeryGimenez

Is there any progress regarding this issue?

gevezex avatar Dec 09 '22 08:12 gevezex

using BinarySignature(...) for the wsse parameter, rather than in the plugin array fixed this for me, and works as intended, as far as i can tell

azban avatar Apr 18 '24 15:04 azban