'Retrieve the redirect url from an exception object'

def _get_redirect_url(self, webhdfs_ex):

    try:
        http_error = webhdfs_ex.get_parent_ex()
        if (http_error is None):
            raise webhdfs_ex
        if (http_error.response.status_code not in (301, 302, 303, 307)):
            LOG.error(('Response    is    not    a    redirect:    %s' % webhdfs_ex))
            raise webhdfs_ex
        return http_error.response.headers['location']
    except Exception as ex:
        LOG.exception(('Failed    to    read    redirect    from    response:    %s    (%s)' % (webhdfs_ex, ex)))
        raise webhdfs_ex
