1

I am trying to build a vaccine availability project. I make a request every 4 seconds to check doses for a vaccine,

response = requests.get(https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=770&date=)

At times I face exceptions of Connection Error. I want to add retry functionality to my code, I know there are many answers out there, but they are using the library. I want to build my own retry functionality to understand core mechanics and for fun.

Can anyone help with how it should be implemented?

Humayun Ahmad Rajib
  • 1,502
  • 1
  • 10
  • 22
Arham Shah
  • 61
  • 1
  • 6
  • 1
    If you want to *understand core mechanics and for fun* why don't you try? – Guy May 23 '21 at 08:25
  • Yes, I want to know how to start and what all functionalities should I concern. Whether I should implement a class or not. If anyone can provide any demo code of workings I would be quick to understand.... – Arham Shah May 23 '21 at 08:35
  • 1
    Put the `requests.get()` call inside a try/except block, and if you get ConnectionError, try again. What is the difficulty? – John Gordon May 23 '21 at 19:02
  • Yes, I got it. I have simply placed my `function()` in except block with time.sleep(30). Thanks, Man! – Arham Shah May 24 '21 at 18:09

1 Answers1

0
import requests
import time
def foo():
    try:
        response = response.get("some URL")
    # you can modify exceptions as per your choice
    except Exception as e:
        time.sleep(30)
        foo()
Arham Shah
  • 61
  • 1
  • 6