runtime
302 / 500
question 302 HTTP & API Clients · hard

The pagination walk that loses a page

all_works(opener, base_url) should return every work from an OpenAlex cursor walk as one flat list. Two reports came in: the totals are always one page short of what OpenAlex says, and code that loops over the result crashes with TypeError: list indices must be integers or slices, not str. Find and fix both bugs.

Simulated: this runs against results recorded on real Python.

Functionall_works(opener, base_url)
Walkbase_url + "&" + urlencode({"cursor": cursor}), starting with "*", until meta.next_cursor is None
Returnsone flat list of every work dictionary, in order

Loading your progress…

The pagination walk that loses a page — Python practice · Runtime