<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _query(function,
           consul_url,
           token=None,
           method='GET',
           api_version='v1',
           data=None,
           query_params=None):
    '''
    Consul object method function to construct and execute on the API URL.

    :param api_url:     The Consul api url.
    :param api_version  The Consul api version
    :param function:    The Consul api function to perform.
    :param method:      The HTTP method, e.g. GET or POST.
    :param data:        The data to be sent for POST method. This param is ignored for GET requests.
    :return:            The json response from the API call or False.
    '''

    if not query_params:
        query_params = {}

    ret = {'data': '',
           'res': True}

    if not token:
        token = _get_token()

    headers = {"X-Consul-Token": token, "Content-Type": "application/json"}
    base_url = urllib.parse.urljoin(consul_url, '{0}/'.format(api_version))
    url = urllib.parse.urljoin(base_url, function, False)

    if method == 'GET':
        data = None
    else:
        if data is None:
            data = {}
        data = salt.utils.json.dumps(data)

    result = salt.utils.http.query(
        url,
        method=method,
        params=query_params,
        data=data,
        decode=True,
        status=True,
        header_dict=headers,
        opts=__opts__,
    )

    if result.get('status', None) == http_client.OK:
        ret['data'] = result.get('dict', result)
        ret['res'] = True
    elif result.get('status', None) == http_client.NO_CONTENT:
        ret['res'] = False
    elif result.get('status', None) == http_client.NOT_FOUND:
        ret['data'] = 'Key not found.'
        ret['res'] = False
    else:
        if result:
            ret['data'] = result
            ret['res'] = True
        else:
            ret['res'] = False
    return ret