import requests


def query_phenomizer(usr, pwd,  *hpo_terms):
    """
    Query the phenomizer web tool
    
    Arguments:
        usr (str): A username for phenomizer
        pwd (str): A password for phenomizer
        hpo_terms (list): A list with hpo terms
    
    Returns:
        raw_answer : The raw result from phenomizer
    """
    base_string = 'http://compbio.charite.de/phenomizer/phenomizer/PhenomizerServiceURI'
    questions = {'mobilequery':'true', 'terms':','.join(hpo_terms), 'username':usr, 'password':pwd}
    try:
        r = requests.get(base_string, params=questions, timeout=10)
    except requests.exceptions.Timeout:
        raise RuntimeError("The request timed out.")
        
    if not r.status_code == requests.codes.ok:
        raise RuntimeError("Phenomizer returned a bad status code: %s" % r.status_code)
    
    r.encoding = 'utf-8'
    
    return r