on-internet
← Community

Getting duplicate records with offset pagination in Python

Stack Overflow ·

I'm pulling records from an API into BigQuery using Python. The API only has limit and offset, so I'm just fetching 100 records, adding 100 to the offset and doing the same thing until there are no more records. This is the part I'm using: offset = 0 records = [] while True: r = requests.get(url, params={"limit": 100, "offset": offset}) data = r.json()["records"] if not data: break records.extend(data) offset += 100 I noticed some duplicate IDs in BigQuery and checked the responses. A few IDs were actually returned on different pages. The API sorts by newest first, and records get added all th

Comments

Sign in or sign up to comment and upvote.

No comments yet.