AnsweredAssumed Answered

Pagination makes endless api calls when retrieving page_views

Question asked by Erkan Er on Sep 14, 2017
Latest reply on Sep 15, 2017 by James Jones

I have the following code to retrieve page views of the user with id=123456. The very same code works when I retrieve the entries of a user for a discussion forum. However, when I change the uri to https://learn.canvas.net/api/v1/users/123456/page_views to retrieve the page views, no matter what the page number is, it continues to return the same records over and over again. So, there is no further data maybe, but it continues to retrieve data. That is, it creates an endless while loop. I wonder if you see any problems with the code:

 

npagina=1

control=0

while control==0:

uri = 'https://learn.canvas.net/api/v1/users/123456/page_views?per_page=100&page=' + str(npagina)

r = requests.get(uri, headers=headers)

raw = r.json()  #if no new data, then continues to retrieve duplicate data

if raw != "":

    views = pd.DataFrame(raw)

    if 'id' in views.columns:

          npagina=npagina+1

          page_views = page_views.append(views)

    else:

          control = 1 

Outcomes