Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
3 0 1 3

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.

eikon-data-apiapp-keyconnection-error
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
25.3k 89 12 25

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.


1658149439360.png (19.2 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you very much! It is working perfectly!
Upvote
25.3k 89 12 25

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

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.