6

I am trying use SUDS and am stuck trying to figure out why I can't get authentication to work (or https).

The service I am trying to access is over https with basic digest authentication. Based on the debugs it seems to be using http instead of https. But not really sure what I am missing. Any clue is appreciated.

from suds.client import Client
from suds.transport.http import HttpAuthenticated
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)

def main():
    url = 'https://blah.com/soap/sp/Services?wsdl'
    credentials = dict(username='xxxx', password='xxxx')
    t = HttpAuthenticated(**credentials)
    client = Client(url, location='https://blah.com/soap/sp/Services', transport=t)
    print client.last_sent()

if __name__=="__main__":
    main()

Debug Output:

DEBUG:suds.wsdl:reading wsdl at: https://blah.com/soap/sp/Services?wsdl ... DEBUG:suds.transport.http:opening (https://blah.com/soap/sp/Services?wsdl)
snip ...
File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\reader.py", line 95, in download
fp = self.options.transport.open(Request(url))

File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py", line 173, in open
return HttpTransport.open(self, request)

File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py", line 64, in open
raise TransportError(str(e), e.code, e.fp)

suds.transport.TransportError: HTTP Error 401: Authorization Required

cosarara97
  • 115
  • 2
  • 5
user9303
  • 61
  • 1
  • 1
  • 2
  • First for correctness...It should be just be 'digest authentication' not 'basic digest authentication.' The types of auth are: 'digest' and 'basic.' So I was confusing. – user9303 Jan 02 '12 at 20:55

2 Answers2

7

Suds provides two HttpAuthenticated classes, one in the suds.transport.http module and the second in the suds.transport.https module. It appears your instantiating from suds.transport.http, however since your URL is https://, you may want to try suds.transport.https.HttpAuthenticated.

DRH
  • 7,868
  • 35
  • 42
5

I stumbled upon this problem and found a solution that works for me. My server was using NTLM authentication, so for suds to work with it, I just had to follow the "Windows (NTLM)" section in the documentation.

First install python-ntlm, and then you can write:

from suds.transport.https import WindowsHttpAuthenticated
ntlm = WindowsHttpAuthenticated(username='xx', password='xx')
client = Client(url, transport=ntlm)
mx0
  • 6,445
  • 12
  • 49
  • 54
Daniel Reis
  • 12,944
  • 6
  • 43
  • 71