wiki:ndg_httpsclient

ndg_httpsclient

This is a HTTPS client implementation based on PyOpenSSL for httplib and urllib2.

Releases

0.1.0

Initial release to PyPI.

Examples

  1. Using urllib2 extension:
    >>> from ndg.httpsclient.urllib2_build_opener import build_opener
    >>> opener = build_opener()
    >>> res = opener.open('https://localhost/')
    >>> print("res = %s" % res.read())
    
  2. httplib interface:
    • Make context verify the peer:
      >>> from OpenSSL import SSL
      >>> ctx = SSL.Context(SSL.SSLv3_METHOD)
      >>> verify_callback = lambda conn, x509, errnum, errdepth, preverify_ok: preverify_ok 
      >>> ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
      >>> ctx.set_verify_depth(9)
      >>> ctx.load_verify_locations(None, '/my/cacerts')
      
    • Make a new connection with this context:
      >>> from ndg.httpsclient.https import HTTPSConnection
      >>> conn = HTTPSConnection('localhost', port=443, ssl_context=ctx)
      >>> conn.connect()
      >>> conn.request('GET', '/')
      >>> resp = conn.getresponse()
      >>> print('Response = %s' % resp.read())
      

Repository

 http://proj.badc.rl.ac.uk/svn/ndg-security/trunk/ndg_httpsclient

Unit Tests

See the ndg.httpsclient.test package.


Philip Kershaw 17/01/12