Python SUDS with Windows Authentication (SOAP)

While intergrating Plone with CRM4, I stumbled upon Suds. However, it didn't support NTLM. Then I found python-ntlm, and merged the two libs.

Below is the result.

You can add it at the bottom of suds/transport.py


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

def __init__(self, options):
# try to import ntlm support
try:
from ntlm import HTTPNtlmAuthHandler
except ImportError:
raise Exception("Cannot import python-ntlm module")
return

HttpTransport.__init__(self, options)
self.pm = u2.HTTPPasswordMgrWithDefaultRealm()
self.handler = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(self.pm)
self.urlopener = u2.build_opener(self.handler)
u2.install_opener(self.urlopener)
pass # end class




[code]
from suds import transport
#>>>
from suds import client
#>>>
from suds.options import Options
#>>>
options = Options(username='DOMAIN\username',
password='password')
#>>>
c = client.Client(url='http://0.0.0.0/mscrmservices/2007/CrmServiceWsdl.aspx',
username='DOMAIN\username',
password='password',
transport=transport.WindowsHttpAuthenticated(options))
#>>>
c
#---
<suds.client.client object="" at="" 0x9c3d86c="">
[/code]

Comments

Anonymous said…
Awesome!

A user like 'DOMAIN\User' is going to need two backslashes to be interpreted correctly, though.
Anonymous said…
Hi Chris

I'm relatively new to Python; I get this error when creating the client: AttributeError: WindowsHttpAuthenticated instance has no attribute 'options'

What did I forget?

Thanks
Unknown said…
Is it possible to adapt your code in order to authenticate via Kerberos instead NTLM ?
Milind Bansode said…
Hi,

I am using Python 2.7.1 on Windows machine. I have installed 0.4 version of SUDS but I am getting below exception while importing suds namespace:
ImportError: No module named suds

Please Help.
Thanks in Advance

Popular posts from this blog

Text Sherlock the OpenGrok alternative (Source Code Search Engine)

JotNow, my new blog