def download(url, params=None, accept="xml", **kwds):
    """Helper function to download a file and return its content.

    Parameters
    ----------
    url : string
        The URL to be parsed.

    params : dict (optional)
        Dictionary containing query parameters.  For required keys
        and accepted values see e.g.
        https://api.elsevier.com/documentation/AuthorRetrievalAPI.wadl

    accept : str (optional, default=xml)
        mime type of the file to be downloaded.  Accepted values are json,
        atom+xml, xml.

    kwds : key-value parings, optional
        Keywords passed on to as query parameters.  Must contain fields
        and values specified in the respective API specification.

    Raises
    ------
    ScopusHtmlError
        If the status of the response is not ok.

    ValueError
        If the accept parameter is not one of the accepted values.

    Returns
    -------
    resp : byte-like object
        The content of the file, which needs to be serialized.
    """
    # Value check
    accepted = ("json", "xml", "atom+xml")
    if accept.lower() not in accepted:
        raise ValueError('accept parameter must be one of ' +
                         ', '.join(accepted))
    # Get credentials
    key = config.get('Authentication', 'APIKey')
    header = {'X-ELS-APIKey': key}
    if config.has_option('Authentication', 'InstToken'):
        token = config.get('Authentication', 'InstToken')
        header.update({'X-ELS-APIKey': key, 'X-ELS-Insttoken': token})
    header.update({'Accept': 'application/{}'.format(accept)})
    # Perform request
    params.update(**kwds)
    resp = requests.get(url, headers=header, params=params)
    # Raise error if necessary
    try:
        reason = resp.reason.upper() + " for url: " + url
        raise errors[resp.status_code](reason)
    except KeyError:  # Exception not specified in scopus
        resp.raise_for_status()  # Will pass when everything is ok
    return resp
def download ( url , params = None , accept = "xml" , ** kwds ) : accepted = ( "json" , "xml" , "atom+xml" ) if accept . lower ( ) not in accepted : raise ValueError ( 'accept parameter must be one of ' + ', ' . join ( accepted ) ) key = config . get ( 'Authentication' , 'APIKey' ) header = { 'X-ELS-APIKey' : key } if config . has_option ( 'Authentication' , 'InstToken' ) : token = config . get ( 'Authentication' , 'InstToken' ) header . update ( { 'X-ELS-APIKey' : key , 'X-ELS-Insttoken' : token } ) header . update ( { 'Accept' : 'application/{}' . format ( accept ) } ) params . update ( ** kwds ) resp = requests . get ( url , headers = header , params = params ) try : reason = resp . reason . upper ( ) + " for url: " + url raise errors [ resp . status_code ] ( reason ) except KeyError : resp . raise_for_status ( ) return resp
Helper function to download a file and return its content.

    Parameters
    ----------
    url : string
        The URL to be parsed.

    params : dict (optional)
        Dictionary containing query parameters.  For required keys
        and accepted values see e.g.
        https://api.elsevier.com/documentation/AuthorRetrievalAPI.wadl

    accept : str (optional, default=xml)
        mime type of the file to be downloaded.  Accepted values are json,
        atom+xml, xml.

    kwds : key-value parings, optional
        Keywords passed on to as query parameters.  Must contain fields
        and values specified in the respective API specification.

    Raises
    ------
    ScopusHtmlError
        If the status of the response is not ok.

    ValueError
        If the accept parameter is not one of the accepted values.

    Returns
    -------
    resp : byte-like object
        The content of the file, which needs to be serialized.