[英]Implement Retry Functionality for request api in Python without any library
我正在嘗試建立一個疫苗可用性項目。 我每 4 秒請求一次檢查疫苗劑量,
response = requests.get(https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=770&date=)
有時我會遇到Connection Error
的異常。 我想在我的代碼中添加重試功能,我知道那里有很多答案,但他們正在使用該庫。 我想構建自己的重試功能來了解核心機制並獲得樂趣。
任何人都可以幫助它應該如何實施?
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.