Python next() stopiteration error [How to Solve]

The iterator needs an exit condition.
use try/except to solve the problem.
example:

    try:
    	# Set a delay for easy observation
         time.sleep(0.1)
         # Update in the same line, iterate the output
         print("\r", next(pages), end=" ")
     # Iteration exit conditions
    except StopIteration:
        return None
    else:
    	# 递归
        test()

Read More: