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.
Function
all_works(opener, base_url)Walk
base_url + "&" + urlencode({"cursor": cursor}), starting with "*", until meta.next_cursor is NoneReturnsone flat list of every work dictionary, in order