def execute_query(query, params={}, transaction=True, context=""):
    """
    Execute a raw Gremlin query with the given parameters passed in.

    :param query: The Gremlin query to be executed
    :type query: str
    :param params: Parameters to the Gremlin query
    :type params: dict
    :param context: String context data to include with the query for stats logging
    :rtype: dict
    
    """
    if transaction:
        query = "g.stopTransaction(FAILURE)\n" + query

    # If we have no hosts available raise an exception
    if len(_hosts) <= 0:
        raise ThunderdomeConnectionError('Attempt to execute query before calling thunderdome.connection.setup')
    
    host = _hosts[0]
    #url = 'http://{}/graphs/{}/tp/gremlin'.format(host.name, _graph_name)
    data = json.dumps({'script':query, 'params': params})
    headers = {'Content-Type':'application/json', 'Accept':'application/json', 'Accept-Charset':'utf-8'}
    import time
    try:
        start_time = time.time()
        conn = httplib.HTTPConnection(host.name, host.port)
        conn.request("POST", '/graphs/{}/tp/gremlin'.format(_graph_name), data, headers)
        response = conn.getresponse()
        content = response.read()

        total_time = int((time.time() - start_time) * 1000)

        if context and _statsd:
            _statsd.timing("{}.timer".format(context), total_time)
            _statsd.incr("{}.counter".format(context))


    except socket.error as sock_err:
        if _statsd:
            total_time = int((time.time() - start_time) * 1000)
            _statsd.incr("thunderdome.socket_error".format(context), total_time)
        raise ThunderdomeQueryError('Socket error during query - {}'.format(sock_err))
    except:
        raise
    
    logger.info(json.dumps(data))
    logger.info(content)

    try:
        response_data = json.loads(content)
    except ValueError as ve:
        raise ThunderdomeQueryError('Loading Rexster results failed: "{}"'.format(ve))
    
    if response.status != 200:
        if response_data in 'message' and len(response_data['message']) > 0:
            graph_missing_re = r"Graph \[(.*)\] could not be found"
            if re.search(graph_missing_re, response_data['message']):
                raise ThunderdomeGraphMissingError(response_data['message'])
            else:
                raise ThunderdomeQueryError(
                    response_data['message'],
                    response_data
                )
        else:
            if _statsd:
                _statsd.incr("{}.error".format(context))
            raise ThunderdomeQueryError(
                response_data['error'],
                response_data
            )

    return response_data['results']
dataset/ETHPy150Open StartTheShift/thunderdome/thunderdome/connection.py/execute_query/swapped operands of `in`