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

3

7

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.

Were answered 25/3, 2010 at 14:57 Comment(0)
F
6

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)
Fickle answered 25/3, 2010 at 15:8 Comment(3)
I'll edit the question right away, but I've tried this and I get timeouts trying to connect to the server, or Error 54 - connection reset by peer. The service continues to work by way of cURL, though.Were
Which server are you trying to connect?A local one? Do you see client calls on server log?Fickle
Regrettably, no; I'm connecting to our client's Microsoft CRM metadata service. It's a pain in the ass, because it's managed by a third-party consulting firm.Were
A
1

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

Abubekr answered 23/8, 2012 at 4:43 Comment(0)
A
0

You can use CNTLM as a local proxy service which will handle all the NTLM authentication calls. Then you just reference the local CNTLM proxy IP and port with no authentication using soapy or urllib2... whatever really.

I've yet to find a python library that deals with complex proxies well.

Abubekr answered 23/8, 2012 at 4:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.