C2W2 Assignment 2: Issue with exercise 3

Issue:

Code for exercise 3:

def paginated_with_next_new_releases(endpoint_request: Callable, url: str, access_token: str) -> list:
    """Manages pagination for API requests done with the endpoint_request callable

    Args:
        endpoint_request (Callable): Function that performs API request
        url (str): Base URL for the request
        access_token (str): Access token

    Returns:
        list: Responses stored in a list
    """
    responses = []
        
    next_page = url
    
    kwargs = {
            "url": url,
            "access_token": access_token,
            "next": ""
        }
    
    while next_page:
        
        ### START CODE HERE ### (~ 4 lines of code)
        # Call the endpoint_request() function with the arguments specified in the kwargs dictionary.
        response = endpoint_request(**kwargs)
        # Use extend() method to add the albums' items to the list of responses.
        responses.extend(response.get('albums').get('items'))
        # Reassign the value of next_page as the 'next' value from the response["albums"] dictionary.
        next_page = response.get('albums').get('next')
        # Update the kwargs dictionary: set the value of the key 'next' as the variable next_page.
        kwargs["next"] = next_page
        ### END CODE HERE ###
        
        print(f"Executed request with URL: {response.get('albums').get('href')}.")
                
    return responses
    

As you can see, the code in the cell actually works and produces output, with first result being a Taylor Swift album:

All other test cases and exercises have passed except this one.

Perhaps you’re not supposed to hard-code the key “albums”?

Just guessing, I’m not a mentor for that course.

You must use key albums because it’s returned by the Spotify API.
Other exercises use the same key and have passed the test cases.

1 Like