I'm using the Eikon Data Api in a Python script that makes a get_news_headlines call every x minutes/hours. About 50% of the time I get this error: eikon.eikonError.EikonError: Error code 408 | Request timeout occured.
Looking for any ideas on how to fix this?
while True: try: headlines = ek.get_news_headlines(query='Language:LEN AND Source:RTRS',20,datetime.datetime.now().utcnow() - datetime.timedelta(minutes=x), datetime.datetime.now().utcnow()) time.sleep(x) except (ek.EikonError): print("Error")
Hi,
time.sleep() has a none visible effect: it's freezing all the thread, including the code that's sending the request and waiting for the response.
If you pause your code with time.sleep() function for a long time (more than several seconds), you shoudl replace with one another solution (x should be given in seconds):
from datetime import datetime, timedelta from threading import Event timer_event = Event() while True: try: headline = ek.get_news_headlines(query='Language:LEN AND Source:RTRS', count=20, date_from=datetime.now().utcnow() - timedelta(minutes=x), date_to=datetime.now().utcnow()) timer_event.wait(timeout=x*60) except(ek.EikonError): print("Error")
or :
from datetime import datetime, timedelta import asyncio while True: try: headline = ek.get_news_headlines(query='Language:LEN AND Source:RTRS', count=20, date_from=datetime.now().utcnow() - timedelta(minutes=x), date_to=datetime.now().utcnow()) asyncio.get_event_loop().run_until_complete(asyncio.sleep(x)) except(ek.EikonError): print("Error")