401 error after a certain number of API calls using python

Hi guys,

I have created a python script that makes a call to the API using the requests library. After each call I am checking for any latest filed accounts and pulling the url for that document, then making another requensts call to that to download the pdf.

The script works fine but after iterating over a set of company registrations (this morning I made a call the API around 75 times in over an hour - as it takes my whole function about a minute to do what I need it to per record before moving to the next one) but then I start to get a 401 error. Weirdly, if I then log in to my developer account, and then start the script again, it seems to work again for a while.

I don’t believe I am exceeding the rate limit - as you can see it’s a slow process per record, so I am unsure what the issue might be? Is it something around authentication?

Here is the lines of code where I am making the initial call:

for company in company_id:
# url to send
url = f"https://api.company-information.service.gov.uk/company/{company}/filing-history"

    # store response
    response = requests.get(url,auth=(API_KEY,''), verify=False)

NB I had to set the verify=False in the requests method to get it to work in the first place.

Am I missing something obvious that might be causing my issue?

Thanks in advance.