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

Best Answer

  • Gurpreet
    Answer ✓

    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')

Answers

  • 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}])