Search code examples
pythonsoappysimplesoap

Problems to authenticate correctly with pysimplesoap


I'm trying to use pysimplesoap to communicate with the Websitepanel SOAP-API. The WebsitePanel API Introduction says:

For interacting with WebsitePanel API you should use Basic Authentication. WebsitePanel recognizes “Authorization” header with the user credentials provided in the following format: username:password

My first try was the following:

client = SoapClient(wsdl=endpoint_url, trace=True)
client['Authorization'] = "%s:%s" % (username, password)

which returns a 401 "Unauthorized". Second try was:

client = SoapClient(wsdl=endpoint_url, trace=True)          
client['wsse:Security'] = {
    'wsse:UsernameToken': {
        'wsse:Username': username,
        'wsse:Password': password,
    }
}    

which works as expected but returns the following:

status: 500
content-length: 924
x-aspnet-version: 4.0.30319
x-powered-by: ASP.NET
server: Microsoft-IIS/7.5
cache-control: private
date: Tue, 12 Feb 2013 14:23:56 GMT
content-type: text/xml; charset=utf-8

And

pysimplesoap.client.SoapFault: q0:Security: SOAP response should be signed.

Why does client['Authorization'] not work and what is meant by the Response should be signed error message?

Thanks in advance.


Solution

  • I figured it out: To authenticate correctly with pysimplesoap you have to call

    client = SoapClient(wsdl=u, trace=True, 
                        http_headers={'Authorization': 'Basic %s' % encoded})
    

    with encodedbeeing the base64-encoded string username:password