norrisp90 0 Newbie Poster

Hi, I've been trying to write a Python client to access a SOAP webservice through our companys authenticated proxy server using the SUDS lib. The proxy uses basic username:password authentication not NTLM and I have been able to get basic downloads working through it using URLLIB2 like this:

passmanager =  urllib2.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None,'http://XXX.XXX.XXX.XXX:80','XXUsernameXX','XXPasswordXX')
proxy_auth_handler = urllib2.ProxyBasicAuthHandler(passmanager)
proxy_support = urllib2.ProxyHandler({'http' : 'http://XXX.XXX.XXX.XXX:80'})

opener = urllib2.build_opener(proxy_support, proxy_auth_handler)

urllib2.install_opener(opener)

and then download as normal using that opener.

I've also managed to get XML-RPC requests to work through it using XMLRPCLIB and a piece of code I found:

class UrllibTransport(xmlrpclib.Transport):
def set_proxy(self, proxy):
    self.proxyurl = proxy

def request(self, host, handler, request_body, verbose=0):
    type, r_type = splittype(self.proxyurl)
    phost, XXX = splithost(r_type)

    puser_pass = None
    if '@' in phost:
        user_pass, phost = phost.split('@', 1)
        if ':' in user_pass:
            user, password = user_pass.split(':', 1)
            puser_pass = base64.encodestring('%s:%s' % (unquote(user),unquote(password))).strip()

    urlopener = urllib.FancyURLopener({'http':'http://%s'%phost})
    if not puser_pass:
        urlopener.addheaders = [('User-agent', self.user_agent)]
    else:
        urlopener.addheaders = [('User-agent', self.user_agent),('Proxy-authorization', 'Basic ' + puser_pass) ]

    host = unquote(host)
    f = urlopener.open("http://%s%s"%(host,handler), request_body)

    self.verbose = verbose
    return self.parse_response(f)

if __name__ == '__main__':
    proxy = "http://XXUSERNAMEXX:XXPASSWORDXX@XXX.XXX.XXX.XXX:80"
    p = UrllibTransport()
    p.set_proxy(proxy)

But I haven't been able to get SUDS to work through it. I've tried setting the proxy using the example given of:

d = dict(http='XXUSERNAMEXX:XXPASSWORDXX:XXX.XXX.XXX.XXX:80')
client.set_options(proxy=d)

But it's not working. Is there a way to define a custom transport for SUDS to use the URLLIB settings I know already work or another SOAP lib that works better with proxys?

Thanks.