Catching ERROR while using ek.set_app_key() function in Python

Hello everyone, I'd like to catch the error displayed by the function ek.set_app_key() when I pass a wrong key.

Can you please help me to do so using Python. I want to raise an error when the app key is wrong. I tried Try and Except but it seems that the message diplayed by ek.set_app_key() is not recognized as an error by python.


Thank you for your help.

Best Answer

  • umer.nalla
    Answer ✓

    Hi @Oussama

    I just heard back from another Eikon API developer who advised the following solution:

    ek = rd.eikon
    ek.set_app_key("junk")
    if rd.session.get_default().open_state == rd.OpenState.Opened:
    print("Opened")
    else:
    print("Failed")

    1658149439360.png

    Apologies for the misinformation earlier.

Answers

  • Hi @Oussama

    I have been advised by the Eikon Data API team that this is not possible.

    One option could be to call get_data with a try-except - just after the set_app_key call to see if the set_app_key worked?

    The other possible option is to use the newer RD Library for Python with a Desktop Connection.
    Once you call open_session, you can then check the session state e.g.

    rd.open_session('desktop.workspace')
    rd.session.get_default().open_state

    OR

    desktop_session = rd.open_session('desktop.workspace')
    desktop_session.open_state

    You can find out more about the RD Library @ - Refinitiv Data Library for Python | Refinitiv Developers

  • Thank you very much! It is working perfectly!