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
解决方案
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.