Suppress error text while requesting data in Eikon API

I am testing the validity of a RIC trying both "try.. Except" (as suggested also here) and "With Suppress" functions to continue the loop and get correct RICs into a list. Although, the code works and adds correct RICs to the list I still see the message telling the RIC is incorrect. Please see attached the screenshot and putting one of them here below as well: try_except.png

RICs = ['NDXl1721A8290.U^L21', 'NDXl1721A8275.U^L21', 'NDXd1621A6275.U^D21','NDXd1621A6300.U^D21']

valid_rics = []

for RIC in RICs:

with suppress(ek.EikonError):

a = ek.get_timeseries(RIC, fields = ['CLOSE'], start_date = '2021-01-01', end_date ='2021-04-18',interval='daily' )

valid_rics.append(RIC)

valid_rics

Is there a way to hide that? Please also note that error text appeared while using the loop and it is ignored when the code is run without a loop for a single RIC.

I would appreciate if you help to find a way of suppressing error message while using the loop.


Tagged:

Best Answer

  • Hi @haykaz.aramyan,

    Messages arn't displayed because of an EikonError exception, it's logged as warnings.
    That's why "with suppress(ek.EikonError)" has no effect.

    There is mainly 3 options to stop warning at screen:

    1. Disable all warnings (from any lib):
      import warnings
      warnings.filterwarnings("ignore")
    2. Disable displayed warnings from eikon:
      import logging
      import eikon as ek
      ...
      ek.set_app_key("xxxxxxxxxx")
      logger = logging.getLogger("pyeikon")
      logger.propagate = False
      ...
    3. Reduce log level to ERROR (warnings will be ignored):
      import logging
      import eikon as ek
      ...
      ek.set_app_key("xxxxxxxxxx")
      ek.set_log_level(logging.ERROR)
      ...

Answers