'Return data from API Python

Im trying to fetch data from a API and worked something out like this below. I get the following error: response 200TypeError: list indices must be integers or slices, not str I get this has to do with my API call but when i change str to int it doesnt solve the problem. Could someone help me with this?

headers = CaseInsensitiveDict()
headers["Accept"] = "application/json"
headers["Authorization"] = "Bearer xx"


total_results = []

for page_num in range(1, 7):
    # Build the URL and download the results
    url = "url" + str(page_num)
    print("Downloading", url)
    response = requests.get(url,headers=headers)
    data = response.json()
    total_results = total_results + data['results']


print("We have", len(total_results), "total results")

error: Downloading xxx: list indices must be integers or slices, not str Traceback (most recent call last):

TypeError: list indices must be integers or slices, not str



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source