This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author marcelo_fernandez
Recipients jjlee, marcelo_fernandez, orsenthil
Date 2009-04-29.22:07:02
SpamBayes Score 2.1814061e-05
Marked as misclassified No
Message-id <1241042824.9.0.796322780597.issue3466@psf.upfronthosting.co.za>
In-reply-to
Content
The workaround I posted before doesn't work with Python 2.6. This one
works (at least) with Python 2.5 *and* Python 2.6:

import httplib 
import urllib2

key_file = 'mykey.pem'
cert_file = 'mycert-signed.pem'

class HTTPSClientAuthConnection(httplib.HTTPSConnection):
    def __init__(self, host, timeout=None):
        httplib.HTTPSConnection.__init__(self, host, key_file=key_file,
cert_file=cert_file)
        self.timeout = timeout # Only valid in Python 2.6

class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
    def https_open(self, req):
        return self.do_open(HTTPSClientAuthConnection, req)

This is a little class to use it:

class Connection(object):

    def __init__(self, url):
        # TODO: Validate/Sanitize the url
        self.url = url
        self._cookiejar = cookielib.CookieJar()

    def send(self, **data):
        parameters = urllib.urlencode(data)
        opener =
urllib2.build_opener(HTTPHandler(debuglevel=DEBUG_LEVEL),
HTTPSClientAuthHandler(debuglevel=DEBUG_LEVEL),
HTTPCookieProcessor(self._cookiejar))
        req = Request(self.url, parameters)
        server_response = opener.open(req).read()
        print server_response
        return server_response

Regards
History
Date User Action Args
2009-04-29 22:07:05marcelo_fernandezsetrecipients: + marcelo_fernandez, jjlee, orsenthil
2009-04-29 22:07:04marcelo_fernandezsetmessageid: <1241042824.9.0.796322780597.issue3466@psf.upfronthosting.co.za>
2009-04-29 22:07:03marcelo_fernandezlinkissue3466 messages
2009-04-29 22:07:02marcelo_fernandezcreate