Python SUDS: Using proxy

Suds is a lightweight SOAP python client for consuming Web Services. As my other developers I ran into the problem that my SUDS client did not connect via a proxy server to a desired URL.

One can find lots of tipps requiring an indecent amount of custom code, which I did not fancy. Below I present a solution with only a small number of lines of code to achieve the desired goal.


Digging into the code of SUDS and some other useful modules I found that the proxy settings are used for sending requests and receiving responses, but not for the initial retrieval of the wsdl definitions. Fortunately I noticed that SUDS uses sessions, which allows for a very simple solution.


import requests
import suds
import suds_requests

url = "https://.......?wsdl"
proxy = { 
'http': "http://......:8080", 
'https': "http://.......:8080", }

data = { 
"login-form-type": "pwd", 
"username": "", 
"password": "", 
"fe11y": "" }

session = requests.Session()
session.verify = False
session.proxies = proxy

r = 

transport = suds_requests.RequestsTransport(session=session, cookies=r.cookies)
client = suds.client.Client(url, transport=transport, proxy=proxy)

In this example solution the proxy information is set in the session object. As this was a test setup with a self-signed certificate the verify attribute of the session is set to False. In a productive solution you wouldn't do that. The proxy server requires an authentication with username and password on a web frontend. So the dictionary data holds the POST data for the login at the proxy. The login is performed using the sessions post method. To keep the authentication status for further requests via the proxy the cookies from the response are extracted.

For the sake of simplicity I use the suds_requests module, which provides the RequestsTransport class, which is derived from suds.transport and uses the requests module to handle requests/responses.

To send and receive via the proxy with SUDS a RequestsTransport object is initiated. As arguments the session object and retrieved cookies are given. Finally the SUDS client is initiated with the RequestsTransport object.

Now have fun with your SOAP calls.