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'
Best Answer
-
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)0
Answers
-
5010202012 seems to be an invalid TRBC Sector code.
0 -
Many thanks Gurpreet @Gurpreet, there may be many of these invalid TRBC Activity Codes although I received them from Refinitiv Support Desk.
0 -
Gurpreet @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']
0 -
Alex Putkov could you please advise here?
0 -
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']
0 -
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: 50103010140 -
Many thanks for that, Gurpreet, this is very useful.
0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 683 Datastream
- 1.4K DSS
- 613 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 626 Refinitiv Data Platform Libraries
- 5 LSEG Due Diligence
- 1 LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 84 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛