def request(url, method = "get", data = False, limit = config.max_api_pages):

    status = False
    req = urllib2.Request(url)
    if data:
        req = urllib2.Request(url, json.dumps(data))
    try: 
        req.get_method = lambda: method.upper()
        res = urllib2.urlopen(req)
        status = True
        res_data = json.loads(res.read()) 
        res_headers = res.info()
    except urllib2.URLError as e:
        res = e
    except urllib2.HTTPError as e:
        res = e
    except __HOLE__ as e:
        return res, status
    except any as e:
        res = e
    if not status:
        return res, status

    # decide whether to return now or continue recursing
    if limit == 0 or not "link" in res_headers.keys(): 
        return res_data, status

    next_url_match = re.match(r"<(?P<next_url>[^>]+)>; rel=\"next\"", res_headers['Link'])
    # if there isn't another url, return current response data
    if not next_url_match:
        return res_data, status

    # get the next urls data
    next_url = next_url_match.group("next_url")
    next_data, status = request(next_url, method, data, int(limit) - 1)

    # api call failed. Return whatever was returned - assume entire api call failed
    if not status:
        return next_data, status
    # successfully return everything
    return res_data + next_data, status
dataset/ETHPy150Open jonmorehouse/vimhub/lib/github.py/request