0

How do I call a web service method when using python 'requests' library? My code looks like this:

import requests

CERT = r'/path/to/cert.crt' #Client certificate
KEY = r'/path/to/key.key' #Client private key
CACERT = r'/path/to/ca.crt' #Server certificate chain

session = requests.Session()
session.cert = (CERT, KEY)
resp = session.get('http://www.smartcallesb.co.za:8091/SmartcallServices2/SmartloadService?wsdl',
                   verify=CACERT)

#print resp.content
session.close()

How would you amend the above code to call a web service function called 'getDealerBalance()'? Please illustrate. If it is not possible is there a way to do this in python? If so please help me with an example. Thank you.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
yusha uzumo
  • 211
  • 1
  • 4
  • 15
  • 1
    Could you provide more information on the web service function? Is it exposed as a URL endpoint that you are able to hit? – Qichao Zhao Nov 25 '16 at 17:17
  • No. It is not exposed as a url end point. The only thing I have is the wsdl: http://www.smartcallesb.co.za:8091/SmartcallServices2/SmartloadService?wsdl – yusha uzumo Nov 25 '16 at 17:45
  • 1
    Check this answer out - seems it will be what you need! http://stackoverflow.com/a/26506633/7145986 – Qichao Zhao Nov 25 '16 at 17:52
  • Thanks. I'll try it – yusha uzumo Nov 25 '16 at 18:48
  • I tried to follow the example using the 'requests' library and added both a body and headers and printed resp.json() and I get the error 'ValueError: No JSON object could be decoded'. The 'suds' library example seem to be close to what I had in mind but it does not seem to apply security using mutual certificates, that is use client certificate client private key and server public certificate. – yusha uzumo Nov 26 '16 at 13:33
  • How can I change the suds example to use mutual certificates as I described? I did search for suds example but did not find one that fits exactly what I want. – yusha uzumo Nov 26 '16 at 13:42

0 Answers0