I have a function that adds API requests to a list, I would like to loop over the requests until the value of 'next_page' is None. My current code is returning the error:
TypeError: can only concatenate str (not "NoneType") to str
When I print out my results I see that my function is trying to concatenate a 'None' value - how can I stop it doing this? I've tried adding in another if statement if next_page != 'None':
but I am still getting the same result.
Here is my function:
pages = []
def build_requests(request):
request = 'https://api.performancehorizon.com' + request
job = requests.get(request, headers=headers, params=params)
req = job.json()
hypermedia_np = req['hypermedia']['pagination']['next_page']
pages.append(request)
while hypermedia_np is not None or hypermedia_np != 'None':
next_page = req['hypermedia']['pagination']['next_page']
print(next_page)
if next_page != 'None':
pages.append(next_page)
job = requests.get('https://api.performancehorizon.com' + next_page, headers=headers, params=params)
req = job.json()
hypermedia_np = req['hypermedia']['pagination']['next_page']
print("Done!")