import requests


def _get_data_from_goodreads_api(user_id, api_key, page_no):
    """Retrieve data about the reviews of a given user from the Goodreads API.
    Returns a Request object if successful, raises an Exception if not.

    :param user_id: The ID of the Goodreads user.
    :param api_key: The Goodreads API key.
    :param page_no: Which page of reviews to fetch.

    """
    # reviews.list (https://www.goodreads.com/api/index#reviews.list) gets
    # all the books on somebody's shelf.
    req = requests.get('https://www.goodreads.com/review/list.xml', params={
        'v': '2',
        'key': api_key,
        'id': user_id,
        'page': str(page_no),
    })
    if req.status_code != 200:
        raise Exception(
            'Unexpected error code from Goodreads API: %s\n'
            'Error message: %r' % (req.status_code, req.text)
        )
    return req