def make_request(url, method='GET', headers=None, timeout=30, **kwargs):
    """A wrapper around requests to set defaults & call raise_for_status()."""
    headers = headers or {}
    headers['User-Agent'] = 'treeherder/{}'.format(settings.SITE_HOSTNAME)
    # Work around bug 1305768.
    if 'queue.taskcluster.net' in url:
        headers['x-taskcluster-skip-cache'] = 'true'
    response = requests.request(method,
                                url,
                                headers=headers,
                                timeout=timeout,
                                **kwargs)

    if response.history:
        params = {
            'url': url,
            'redirects': len(response.history),
            'duration': sum(r.elapsed.total_seconds() for r in response.history)
        }
        newrelic.agent.record_custom_event('RedirectedRequest', params=params)

    response.raise_for_status()
    return response
def make_request ( url , method = 'GET' , headers = None , timeout = 30 , ** kwargs ) : headers = headers or { } headers [ 'User-Agent' ] = 'treeherder/{}' . format ( settings . SITE_HOSTNAME ) if 'queue.taskcluster.net' in url : headers [ 'x-taskcluster-skip-cache' ] = 'true' response = requests . request ( method , url , headers = headers , timeout = timeout , ** kwargs ) if response . history : params = { 'url' : url , 'redirects' : len ( response . history ) , 'duration' : sum ( r . elapsed . total_seconds ( ) for r in response . history ) } newrelic . agent . record_custom_event ( 'RedirectedRequest' , params = params ) response . raise_for_status ( ) return response
A wrapper around requests to set defaults & call raise_for_status().