<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(lamp_id, state, action='', method='GET'):
    '''
    Query the URI

    :return:
    '''
    # Because salt.utils.query is that dreadful... :(

    err = None
    url = "{0}/lights{1}".format(CONFIG['uri'],
                                 lamp_id and '/{0}'.format(lamp_id) or '') \
          + (action and "/{0}".format(action) or '')
    conn = http_client.HTTPConnection(CONFIG['host'])
    if method == 'PUT':
        conn.request(method, url, salt.utils.json.dumps(state))
    else:
        conn.request(method, url)
    resp = conn.getresponse()

    if resp.status == http_client.OK:
        res = salt.utils.json.loads(resp.read())
    else:
        err = "HTTP error: {0}, {1}".format(resp.status, resp.reason)
    conn.close()
    if err:
        raise CommandExecutionError(err)

    return res