I am downloading historic data from NSE site and running below code. It is give TIMEOUT error for public holidays as data in not available for those days. How can I ignore this error and let the loop continue for next date.
from datetime import date, datetime
from pandas.tseries.offsets import BDay
from jugaad_data.nse import bhavcopy_fo_save
i=0
while i<2610:
Date = (datetime.today() - BDay(i)).date()
bhavcopy_fo_save(Date, r"C:\Users\Mohit\ALGO_TRADING\bhavcopy")
i=i+1
I have pasted error screenshot as below-
Thanks,
Mohit
>Solution :
What you could do is to wrap the code that might throw the exception in a try-except block.
So for instance:
try:
bhavcopy_fo_save(Date, r"C:\Users\Mohit\ALGO_TRADING\bhavcopy")
catch TimeoutError as e:
pass
Instead of pass you could print the error or something else that acknowledges that the error occured, but it will no longer stop the program.