Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has anyone combined soap.py or suds with python-ntlm?

I'd like to replace an app's current (badly busted and crufty) cURL-based (cURL command-line based!) SOAP client with suds or soap.py. Trouble is, we have to contact an MS CRM service, and therefore must use NTLM. For a variety of reasons the NTLM proxy is a bit of a pain to use, so I'm looking into python-ntlm to provide that support.

Can suds or soap.py be made to use this authentication method? If so, how? If not, any other suggestions would be fantastic.

Edit

As noted below, suds already supports python-ntlm out of the box.

like image 500
Chris R Avatar asked Mar 25 '10 14:03

Chris R


2 Answers

Suds was fixed to support it since 0.3.8.

Sources of python-suds-0.3.9\suds\transport\https.py says:

class WindowsHttpAuthenticated(HttpAuthenticated):
    """
    Provides Windows (NTLM) http authentication.
    @ivar pm: The password manager.
    @ivar handler: The authentication handler.
    """

    def u2handlers(self):
        # try to import ntlm support  
        try:
            from ntlm import HTTPNtlmAuthHandler
        except ImportError:
            raise Exception("Cannot import python-ntlm module")
        handlers = HttpTransport.u2handlers(self)
        handlers.append(HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(self.pm))
        return handlers

Try with the following snippet as described here:

from suds.transport.https import WindowsHttpAuthenticated
ntlm = WindowsHttpAuthenticated(username='xx', password='xx')
client = Client(url, transport=ntlm)
like image 157
systempuntoout Avatar answered Oct 18 '22 10:10

systempuntoout


Another approach would be to call your curl command during soap exceptions and then initiate a retry.

something like...

curl -x websenseproxy:8080 --ntlm -U domain\user:password --insecure https://blah.com/prod/webservice.asmx?WSDL

#insecure is used for self signed certs

like image 33
Wes Avatar answered Oct 18 '22 11:10

Wes