sharepoint rest api – Query string prohibited depending on the statement

The problem

I have a List with loads of rows and I’m doing a workaround in Python to fetch them without exceding the list view threshold. So far I managed to do this by limiting the ID range of the results, like so:

<...>/_api/Web/lists/GetByTitle('<ListName>')/Items?$select=ID&$top=5000&$orderby=ID&$filter=ID ge 1 and ID le 5000

And then I change the numbers of ‘ID’ column from 1~5000 to 5001~10000, and so on…

Some Queries

So this query here works fine:

<...>/_api/Web/lists/GetByTitle('<ListName>')/Items?$select=*&$top=5000&$orderby=ID&$filter=ID ge 20001 and ID le 25000 and TextField eq 'Some text'

And I manage to get 5000 rows from each request made like this (even though there are more than 5000 rows with ‘Some text’ inside the ‘TextField’ column).

But if I try this one here:

<...>/_api/Web/lists/GetByTitle('<ListName>')/Items?$select=*&$top=5000&$orderby=ID&$filter=ID ge 20001 and ID le 25000 and DateField gt '2020-09-12T00:00:00'

It raises me the limit exception. And if I change the date to a day that I know it’ll rerturn less then 5000 rows, it runs just fine.

In Sum

I’m limiting the range with the ID column of SharePoint list so it doesn’t exceed the view threshold, but it doesn’t seem consistent.

This is the template i’m using, adding things at the end, and only changing the range until the list is over:

<...>$filter=ID ge 1 and ID le 5000 and <other query options...>

Any ideas on why SharePoint thinks I’m trying to fetch more than 5000 rows at once? Thanks in advance!