Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python SUDS SOAP request to https service 401

Tags:

python

https

suds

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

like image 358
user9303 Avatar asked Jan 02 '12 03:01

user9303


2 Answers

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.

like image 145
DRH Avatar answered Nov 17 '22 22:11

DRH


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)
like image 5
Daniel Reis Avatar answered Nov 17 '22 21:11

Daniel Reis