Python SOAP client with Zeep - authentication

前端 未结 3 1292
臣服心动
臣服心动 2020-12-28 10:58

I am trying to use Zeep to implement a SOAP client, as it seems the only maintained library at the moment:

  • ZSI looked very good but its latest
相关标签:
3条回答
  • 2020-12-28 11:29

    In my case the API I was working with required WS-Security (WSSE) rather than HTTP.

    from zeep import Client
    from zeep.wsse.username import UsernameToken
    
    client = Client(<wsdl_url>, wsse=UsernameToken(<username>, <password>)
    
    0 讨论(0)
  • 2020-12-28 11:36

    Probably with the newer Version of zeep the older solution does not work anymore. Here is the new way:

    from requests.auth import HTTPBasicAuth  # or HTTPDigestAuth, or OAuth1, etc.
    from requests import Session
    from zeep import Client
    from zeep.transports import Transport
    
    session = Session()
    session.auth = HTTPBasicAuth(user, password)
    client = Client('http://my-endpoint.com/production.svc?wsdl',
                transport=Transport(session=session))
    
    0 讨论(0)
  • 2020-12-28 11:54

    For Basic Access Authentication you can use the HTTPBasicAuth class from the requests module, as explained on Zeep documentation http://docs.python-zeep.org/en/master/transport.html:

    from requests.auth import HTTPBasicAuth  # or HTTPDigestAuth, or OAuth1, etc.
    from zeep import Client
    from zeep.transports import Transport
    
    client = Client('http://my-endpoint.com/production.svc?wsdl',
        transport=Transport(http_auth=HTTPBasicAuth(user, password)))
    
    0 讨论(0)
提交回复
热议问题