-def make_cert_handler(key_file=None, cert_file=None):
- if cert_file is None:
- cert_file = key_file
-
- class HTTPSCertConnection(httplib.HTTPSConnection):
- def __init__(self, host):
- httplib.HTTPSConnection.__init__(self, host,
- key_file=key_file,
- cert_file=cert_file)
-
- class HTTPSCertHandler(mechanize.HTTPSHandler):
- def https_open(self, req):
- return self.do_open(HTTPSCertConnection, req)
-
- return HTTPSCertHandler
-
-cj = mechanize.CookieJar()
-
-cert_handler = make_cert_handler("cert.pem")
-opener = mechanize.build_opener(mechanize.HTTPRedirectHandler, cert_handler, mechanize.HTTPCookieProcessor(cj))
-mechanize.install_opener(opener)
-