Changeset c3a573c for fedd


Ignore:
Timestamp:
Feb 13, 2015 10:08:10 AM (10 years ago)
Author:
Ted Faber <faber@…>
Branches:
master
Children:
187a8f9
Parents:
36e701e
Message:

Defensive driving around new ssl libraries. Fix error handling in get_url

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/util.py

    r36e701e rc3a573c  
    88
    99import httplib
     10import ssl
    1011
    1112from optparse import OptionParser
     
    216217    ok = False
    217218    failed_exception = None
     219    # Build a context on modern systems, on old ones fall back to the old
     220    # HTTPSConnection definition.
     221    context = None
     222    try:
     223        # This context does not check the self-signed server cert
     224        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
     225        context.load_cert_chain(cf)
     226    except AttributeError:
     227        pass
    218228    while not ok and retries < max_retries:
    219229        try:
    220             conn = httplib.HTTPSConnection(po.hostname, port=po.port,
    221                     cert_file=cf, key_file=cf, timeout=30)
     230            if context is not None:
     231                conn = httplib.HTTPSConnection(po.hostname, port=po.port,
     232                        timeout=30, context=context)
     233            else:
     234                conn = httplib.HTTPSConnection(po.hostname, port=po.port,
     235                        cert_file=cf, key_file=cf, timeout=30)
    222236            conn.putrequest('GET', po.path)
    223237            conn.endheaders()
     
    244258            retries += 1
    245259
    246     if retries > max_retries and failed_exception:
     260    if retries >= max_retries and failed_exception:
    247261        if log:
    248262            log.debug('Raising %s', failed_exception)
    249         raise failed_excpetion
     263        raise failed_exception
    250264
    251265# Functions to manipulate composite testbed names
Note: See TracChangeset for help on using the changeset viewer.