<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">1) I have an application that accesses a web site via HTTPS using a certificate. The primary url returns a 302 redirect, urllib2 then goes to this address and gets a 401, which if the passwordMgr has be setup properly then connects.<div>
<br></div><div>I have been able to determine a set of uri's that if fed to the passwordMgr.add_password() make things work. The problem is that depending on where the application is run from the redirect may be to different url's. I would like to dynamically catch the redirect and then format add_password() properly to add this uri and the user/password information rather than having to determine all possible uri's and load passwordMgr at init time. </div>
<div>If I overload the redirect handler when it gets there I don't have access to the passwordMgr.  Following is a snipit of the code:</div><div><br></div><div><div>                passwordMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()</div>
<div><span style="white-space: pre; ">            </span></div><div>            #### Here I am setting passwordMgr up with all known uri's, but if I get redirected to some other address It no longer works  ####</div><div><span style="white-space: pre; ">          </span>for uri in ('<a href="http://payex.adp.com/" target="_blank" style="color: rgb(42, 93, 176); ">payex.adp.com</a>','<a href="http://agateway.adp.com/" target="_blank" style="color: rgb(42, 93, 176); ">agateway.adp.com</a>','<a href="http://bgateway.adp.com/" target="_blank" style="color: rgb(42, 93, 176); ">bgateway.adp.com</a>','.<a href="http://adp.com/" target="_blank" style="color: rgb(42, 93, 176); ">adp.com</a>'):</div>
<div><span style="white-space: pre; ">                    </span>passwordMgr.add_password(None, uri, usr, pwd)</div><div><span style="white-space: pre; ">      </span></div><div><span style="white-space: pre; ">           </span>basicAuthHndlr = urllib2.HTTPBasicAuthHandler(passwordMgr)</div>
<div><span style="white-space: pre; ">            </span></div><div><span style="white-space: pre; ">           </span>cookies = cookielib.CookieJar()</div><div><span style="white-space: pre; ">            </span>cookieHndlr = urllib2.HTTPCookieProcessor(cookies)</div>
<div><br></div><div><span style="white-space: pre; ">           </span>self.opener = urllib2.build_opener(MultipartPostHandler, HTTPSClientAuthHandler(httpDebug),basicAuthHndlr,cookieHndlr,urllib2.HTTPRedirectHandler())</div><div>
<br></div>I then call:</div><div>               self.opener(request)</div><div><br></div><div>2) I have a second problem, for which I have created an ugly workaround, Namely I need a way to give the HTTPSConnection.__ini__() a reference to the cert file. The HTTPSClientAuthHandler do_open method takes a ref to the HTTPSClientAuthConnection not an instance, so I overloaded this class and get the cert_file via a previously set global ref.  I would like a better way to feed the cert file.  Here is the code I am using:</div>
<div><br></div><div><div>class HTTPSClientAuthConnection(httplib.HTTPSConnection):</div><div><span style="white-space: pre; ">        </span>def __init__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):</div><div><span style="white-space: pre; ">          </span># nb cert_file is global and set in UrllibPX</div>
<div><span style="white-space: pre; ">            </span>httplib.HTTPSConnection.__init__(self, host, cert_file=cert_file)</div><div><br></div><div>doseq = 1<span style="white-space: pre; ">        </span></div><div>class HTTPSClientAuthHandler(urllib2.HTTPSHandler):</div>
<div><span style="white-space: pre; ">    </span></div><div><span style="white-space: pre; ">   </span>def https_open(self, req):</div><div><span style="white-space: pre; ">         </span>for tries in range(3):</div><div><span style="white-space: pre; ">                     </span>try:</div>
<div><span style="white-space: pre; ">                            </span>ret = self.do_open(HTTPSClientAuthConnection, req)</div><div><span style="white-space: pre; ">                         </span>return ret</div><div><span style="white-space: pre; ">                 </span>except URLError:</div>
<div><span style="white-space: pre; ">                            </span>log = logging.getLogger()</div><div><span style="white-space: pre; ">                          </span>log.warn("problem connecting")</div><div><span style="white-space: pre; ">           </span>raise</div>
</div><div><br></div><div><br></div><div>thanks,</div><div><br></div></span><br>-- <br>Max Slimmer<br>