I have a case where I have to keep checking the response of a GET call until I see the status
as success
in the api response. And it takes around 20 to 50 mins to get the status from active
to success
. Only when I see this status I can perform my other action.
How can I achieve that in python?
I tried this polling python library. But it's not much of a help.
This is my code. But it's not working how I want. Is there any other way to do this?
try:
while True:
response = requests.get(f'{os.environ["BASE_URL"]}/syncs/076532', headers=headers)
json_res = response.json()
if json_res.get('status') != 'success':
logging.info("Polling started.......")
logging.info("Waiting.......")
time.sleep(120)
print("Got status as success. Proceeding......")
sys.exit()
except KeyboardInterrupt:
logging.info("exiting")
sys.exit()
Thanks in Advance