Why does my script stop the moment the results list comes back empty? I keep hitting the same traceback.
Your script stops because it reaches for the first element of a list that has no elements in it.
An empty list has no position zero. In most languages, asking for items[0] on a list of length zero raises an error at that exact line rather than returning nothing. The traceback you are seeing is the runtime telling you the position you asked for does not exist yet.
To fix it, check that the list actually holds something before you index into it. For instance, you could write:
if items: first = items[0] else: print("No records came back for that query.")
Happy to look at the surrounding function if the traceback persists.