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
7 1 0 1

KeyError in Python

When trying to enable the eikon Data API using Python, my sample code test.py compilation fails stating KeyError in configparser.py with the App Key generated on Eikon. Any idea on how to resolve this?

1705090729272.png

eikon-data-apipython#technology
1705092125274.png (97.1 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.

Hello @donia.augustine

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?


If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,


AHS

Upvote
Accepted
22.1k 59 14 21

Hi @donia.augustine,

We don't know what's the structure of your config file which is referenced as variable cfg. If the key that you are trying to use is the appKey, then directly use it in the api call like -

ek.set_app_key('35xxxxxx7b')
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.

Upvotes
24.7k 54 17 14

Hello @donia.augustine

The Python configparser uses the following syntax for the cfg file:

[section name]
key1 = value
key2= value

Example:

[workspace]
app_id = XXXXXX7777BBBBB8888

Usage: cfg['section name']['key'] like the following

import eikon as ek
import configparser as cp

cfg = cp.ConfigParser()
cfg.read('credential.cfg')
ek.set_app_key(cfg['workspace']['app_id'])

Based on your error, your code is cfg['section name'][value] which is not the valid format for the configparser.

#your code
ek.set_app_key(cfg['eikon'][{your app key}])




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.