How to connect to a SOAP-based web service with Suds over a proxy that requires authentication
I’m writing a small Python program to connect to a SOAP-based web service using Suds and just ran into an issue with authenticating to our proxy server. I’m able to connect fine if the web service runs on http, but the web service we need to connect to uses https and the urllib2 module threw an error:
urllib2.URLError: <urlopen error Tunnel connection failed: 407 Proxy Authentication Required>
The solution in my case is to upgrade to a newer patch version of Python 2.6 (I upgraded mine to 2.6.6), it looks like the older urllib2 module that I was using didn’t support this scenario as mentioned here, so make sure first that you have at least Python 2.6.4 before trying the sample code below:
from suds.client import Client service_url = 'https://services.domain.com/test/hello.wsdl' proxy_settings = dict(http='http://user:password@host:port', https='http://user:password@host:port') client = Client(service_url, proxy=proxy_settings) print client
Tags: howto, python, tech, software development, networking