Update api.py

Seemed to have fixed the infinite while loop