def connect_to_proxy(req, type1):
    '''Try to sequentially connect to all Domain Controllers in the list
    until one is available and can handle the NTLM transaction.

    @return A tuple with a NTLM_Proxy object and a NTLM challenge (Type 2).'''

    # Get configuration entries in Apache file
    try:
        domain = req.get_options()['Domain']
        pdc = req.get_options()['PDC']
        bdc = req.get_options().get('BDC', False)
    except KeyError, e:
        req.log_error(str(e) % 'PYNTLM: Incorrect configuration for pyntlm = %s', apache.APLOG_CRIT)
        raise
    ntlm_challenge = None
    for server in (pdc, bdc):
        if not server: continue
        try:
            if server.startswith('ldap:'):
                url = urlparse(server)
                decoded_path =urllib.unquote(url.path)[1:]
                req.log_error('PYTNLM: Initiating connection to Active Directory server %s (domain %s) using base DN "%s".' %
                    (url.netloc, domain, decoded_path), apache.APLOG_INFO)
                proxy = NTLM_AD_Proxy(url.netloc, domain, base=decoded_path)
            else:
                req.log_error('PYTNLM: Initiating connection to Domain Controller server %s (domain %s).' %
                    (server, domain), apache.APLOG_INFO)
                proxy = NTLM_DC_Proxy(server, domain)
            ntlm_challenge = proxy.negotiate(type1)
        except Exception, e:
            req.log_error('PYNTLM: Error when retrieving Type 2 message from server(%s) = %s' % (server,str(e)), apache.APLOG_CRIT)
        if ntlm_challenge: break
        proxy.close()
    else:
        raise RuntimeError("None of the Domain Controllers are available.")
    return (proxy, ntlm_challenge)
dataset/ETHPy150Open Legrandin/PyAuthenNTLM2/pyntlm.py/connect_to_proxy/swapped operands of `%`