Ignore:
Timestamp:
Mar 18, 2010 8:35:10 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
114d24b
Parents:
3159f5d
Message:

Improved SSL error handling (more try blocks, BIOError exception)
Separate get_url into util
Work with remote splitter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/util.py

    r3159f5d r1dcaff4  
    55import logging
    66
     7import httplib
     8
    79from M2Crypto import SSL
     10from M2Crypto.SSL import SSLError
    811from fedid import fedid
     12from service_error import service_error
     13from urlparse import urlparse
    914
    1015
     
    169174    d.close()
    170175
     176def get_url(url, cf, destdir, fn=None, max_retries=5):
     177    """
     178    Get data from a federated data store.  This presents the client cert/fedid
     179    to the http server.  We retry up to max_retries times.
     180    """
     181    po = urlparse(url)
     182    if not fn:
     183        fn = po.path.rpartition('/')[2]
     184    retries = 0
     185    ok = False
     186    failed_exception = None
     187    while not ok and retries < 5:
     188        try:
     189            conn = httplib.HTTPSConnection(po.hostname, port=po.port,
     190                    cert_file=cf, key_file=cf)
     191            conn.putrequest('GET', po.path)
     192            conn.endheaders()
     193            response = conn.getresponse()
     194
     195            lf = open("%s/%s" % (destdir, fn), "w")
     196            buf = response.read(4096)
     197            while buf:
     198                lf.write(buf)
     199                buf = response.read(4096)
     200            lf.close()
     201            ok = True
     202        except IOError, e:
     203            failed_excpetion = e
     204            retries += 1
     205        except httplib.HTTPException, e:
     206            failed_exception = e
     207            retries += 1
     208        except SSLError, e:
     209            failed_exception = e
     210            retries += 1
     211
     212    if retries > 5 and failed_exception:
     213        raise failed_excpetion
     214
Note: See TracChangeset for help on using the changeset viewer.