Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /
avatar image
Question by alex.yermolayev · Apr 08, 2020 at 03:07 PM · pythoneikon data apiscreenerheaderskeyerror

Getting KeyError: "headers" from data request

Hello! While trying to search for companies in a specific country under a specific TRBC Activity name (industry or sector basically) with the SCREEN function, I get a KeyError: 'headers' from the screen data request:

Belgium = pd.DataFrame()
for item in TRBC_Sectors:
    country = '"BE"'
    activity = item
    exp = 'SCREEN(U(IN(Equity(active,public,private,primary))), IN(TR.RegCountryCode,{}), IN(TR.TRBCActivityCode,{}), CURN=USD)'.format(country,activity)
    fields = ["TR.CommonName","TR.TRBCActivity"]
    output, err = ek.get_data(exp, fields)
    Belgium = Belgium.append(output)


while TRBC_Sectors is a list with strings for each of the TRBC Activity sectors: e.g.

['5010101010', '5010101011', '5010101012', '5010201010', '5010202010', '5010202011', '5010202012', '5010202013', '5010202014', '5010202015', '5010203010', '5010203011', '5010203012', '5010203013', '5010301010', '5010301011', '5010301012', '5010301013', '5010301014']

Error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-23-8361b97df6fa> in <module>
      5     exp = 'SCREEN(U(IN(Equity(active,public,private,primary))), IN(TR.RegCountryCode,{}), IN(TR.TRBCActivityCode,{}), CURN=USD)'.format(country,activity)
      6     fields = ["TR.CommonName","TR.TRBCActivity"]
----> 7     output, err = ek.get_data(exp, fields)
      8     Belgium = Belgium.append(output)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\data_grid.py in get_data(instruments, fields, parameters, field_name, raw_output, debug)
    195         return result
    196 --> 197     return get_data_frame(result, field_name)
    198     199 
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\data_grid.py in get_data_frame(data_dict, field_name)
    244         headers = [header.get('field', header.get('displayName')) for header in data_dict['headers'][0]]
    245     else:
--> 246         headers = [header['displayName'] for header in data_dict['headers'][0]]
    247     data = pd.np.array([[get_data_value(value) for value in row] for row in data_dict['data']])
    248     if len(data):

KeyError: 'headers'

People who like this

0 Show 1
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
alex.yermolayev · Apr 08, 2020 at 06:07 PM 0
Share

@Alex Putkov could you please advise here?

5 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Gurpreet · Apr 08, 2020 at 06:26 PM

Code here:

TRBC_Sectors = ['5010101010', '5010101011', '5010101012', '5010201010', '5010202010', '5010202011', '5010202012', '5010202013', '5010202014', '5010202015', '5010203010', '5010203011', '5010203012', '5010203013', '5010301010', '5010301011', '5010301012', '5010301013', '5010301014']

Belgium = pd.DataFrame()
for item in TRBC_Sectors:
  try:
    print("Trying sector: %s" % item)
    exp = 'SCREEN(U(IN(Equity(active,public,private,primary))), IN(TR.RegCountryCode, "BE"), IN(TR.TRBCActivityCode,{}), CURN=USD)'.format(item)
    output, err = ek.get_data(exp, ["TR.CommonName", "TR.TRBCActivity"])
    print("Received size: %s" % str(output.size))
    Belgium = Belgium.append(output)
  except Exception as exp:
    print("Error getting data for: %s" % item)

Comment
alex.yermolayev

People who like this

1 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
alex.yermolayev · Apr 08, 2020 at 06:31 PM 0
Share

Many thanks for that, Gurpreet, this is very useful.

avatar image
REFINITIV
Answer by Gurpreet · Apr 08, 2020 at 04:51 PM

5010202012 seems to be an invalid TRBC Sector code.

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
alex.yermolayev · Apr 08, 2020 at 06:05 PM 0
Share

Gurpreet @

No, it is not the problem here. I tried the same screen using TR.TRBCBusinessSectorCode and corresponsing codes (see below) but the error message is the same.

['5010', '5020', '5030', '5110', '5120', '5130', '5210', '5220', '5230', '5240', '5310', '5320', '5330', '5340', '5410', '5420', '5430', '5510', '5560', '5530', '5540', '5550', '5610', '5620', '5710', '5720', '5810', '5910']
avatar image
Answer by alex.yermolayev · Apr 08, 2020 at 04:57 PM

Many thanks Gurpreet @, there may be many of these invalid TRBC Activity Codes although I received them from Refinitiv Support Desk.

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
Answer by alex.yermolayev · Apr 08, 2020 at 06:08 PM

Gurpreet @

No, it is not the problem here. I tried the same screen using TR.TRBCBusinessSectorCode and corresponsing codes (see below) but the error message is the same.

['5010', '5020', '5030', '5110', '5120', '5130', '5210', '5220', '5230', '5240', '5310', '5320', '5330', '5340', '5410', '5420', '5430', '5510', '5560', '5530', '5540', '5550', '5610', '5620', '5710', '5720', '5810', '5910']
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Answer by Gurpreet · Apr 08, 2020 at 06:25 PM

Just use a Try/Catch block to get past invalid sector codes -

Trying sector: 5010101010
Received size: 60
Trying sector: 5010101011
Received size: 12
Trying sector: 5010101012
Received size: 3
Trying sector: 5010201010
Received size: 15
Trying sector: 5010202010
Received size: 18
Trying sector: 5010202011
Received size: 9
Trying sector: 5010202012
Error getting data for: 5010202012
Trying sector: 5010202013
Error getting data for: 5010202013
Trying sector: 5010202014
Error getting data for: 5010202014
Trying sector: 5010202015
Error getting data for: 5010202015
Trying sector: 5010203010
Received size: 42
Trying sector: 5010203011
Received size: 390
Trying sector: 5010203012
Received size: 552
Trying sector: 5010203013
Received size: 24
Trying sector: 5010301010
Error getting data for: 5010301010
Trying sector: 5010301011
Error getting data for: 5010301011
Trying sector: 5010301012
Error getting data for: 5010301012
Trying sector: 5010301013
Error getting data for: 5010301013
Trying sector: 5010301014
Error getting data for: 5010301014
Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
11 People are following this question.

Related Questions

Getting no entries in dataframe using screener exp in get_data in python

Getting CA.C fields via Eikon Data API

Uncaught UnicodeEncodeError on Python 2 in debug statement

Type checking in Python

When will bond search with Python be available in Eikon DAPI?

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges