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
datadefined? Also please provide the full traceback.URL1throughURL6, but I assume that is just for sample purposes. But then your are printingresponse.status_codebefore you even get the response. And why useCaseInsensitiveDict?data.