Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to ingore TIMEOUT error in While loop

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-

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading