Python SUDS SOAP request to https service 401
Asked Answered
F

2

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

Faison answered 2/1, 2012 at 3:40 Comment(1)
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.Faison
M
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.

Macmahon answered 7/1, 2012 at 17:59 Comment(1)
+1. suds.transport.https.HttpAuthenticated wasn't in suds' doc. Your solution was the answer to my problem.Alixaliza
O
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)
Orlosky answered 19/5, 2014 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.