import json


def make_request_callback(timeout_count, body_on_success,
                          http_error_status=504):
    """Make a request callback that timeout a couple of time before returning
    body_on_success.

    Returns:
        A tuple (request_callback, attempts), attempts is an array of size one
        that contains the number of time request_callback has been called.
    """
    # use a list for nonlocal mutability used in request_callback
    attempts = [0]

    def request_callback(request):
        attempts[0] += 1

        if attempts[0] <= timeout_count:
            return http_error_status, {}, "Timeout"
        else:
            resp_body = dict(body_on_success)
            return 200, {}, json.dumps(resp_body)

    return request_callback, attempts