for num in range(0, location_count):
    #for num in range(0, 4):
    running = True
    region = 'Unknown'
    location = location_result['locations'][num]['id']
    # Wrapping the API requests in a while rule
    # This is because we see spurious 400s with no explanation
    # So when we hit that, we back off for 10 seconds and retry until
    # we get a result.
    # NB if there's actually a problem with authentication the script
    # will get stuck here, infinitely
    attempts = 0
    while True:
        attempts += 1
        curl_result = httpCaller.postResultHeaders(
            '/diagnostic-tools/v2/ghost-locations/%s/curl-results' \
            % location, json.dumps(newCurl), verbose)
        if curl_result['statuscode'] != 200:
            retries += 1
            backoff = backoff * 2
            sys.stdout.write(
                "\r%d - %s - Status Code: %s. Rate Limit Remaining: %s. Attempt: %s Retries: %s. Backoff %s"
                % (num, location, str(curl_result['statuscode']),
                   str(curl_result['ratelimit']), attempts, retries, backoff))
            sys.stdout.flush()
            time.sleep(backoff)
            continue
        elif curl_result['ratelimit'] is '0':
            retries += 1
            backoff = backoff * 2
            sys.stdout.write(