Backend error. 400 Bad Request, ESG score retrieval
Dear Developer Community,
I want to download ESG and Pillar scores for all US stocks from 2011 to 2023 on a quarterly basis via the Eikon Data API.
I am using the get_data(..) function with the following specifications
fields = ["TR.TRESGScore", "TR.EnvironmentPillarScore", "TR.SocialPillarScore", "TR.GovernancePillarScore"]
parameters= {'Frq':'Q', 'SDate':'2010-12-31','EDate':'2024-12-31'}
I already have all ISINs from WRDS, saved as a list in Python. Also, I made sure to delete all <NA> entries leaving me with around 14.000 ISINs
I created a chunking function which requests 100 chunks per iteration.
def chunk_list(first, chunk_size):
for i in range(0,len(first), chunk_size):
yield first[i:i + chunk_size]
chunk_size = 100
I used the chunking function with get_data:
for chunk in chunk_list(ISIN_list, chunk_size):
df, err = ek.get_data(chunk, fields=fields, parameters= parameters)
df_complete.append(df)
print(f'{len(chunk)} chunks completed')
Problem Description:
My problem is that the funtion works for the first few iterations but than I get a 400 Bad Request Error.
...
100 chunks completed
100 chunks completed
100 chunks completed
100 chunks completed
100 chunks completed
100 chunks completed
100 chunks completed
100 chunks completed
Backend error. 400 Bad Request
...
refinitiv.dataplatform.errors.RDPError: Error code 400 | Backend error. 400 Bad Request
How I tried solving it:
I searched the forum for similar issues and already did the following:
- I tried using smaller chunks sizes (e.g. 50 and 10), but it did not help
- I tried adding a random sleep timer but it did not help
time.sleep(random.randint(0,3))
I haven't find a solution yet...
The Helpdesk suggested I should ask the Developer Community.
Do you have any suggestions or soltions to my problem?
Thank you very much in advance!
Best Answer
-
Hi @luca.comanici ,
1st, I'd advise using the Refinitiv Library for Python (RD Lib.) which is more stable than the Eikon Data API (EDAPI).
2nd, I would advise coding defensively, using try and except loops; e.g.:
import refinitiv.data as rd
rd.open_session()
def chunk_list(first, chunk_size):
for i in range(0,len(first), chunk_size):
yield first[i:i + chunk_size]
chunk_size = 100
ISIN_list = ['US0378331005', 'GB00B0CWJX34', 'US3696043013']
fields = ["TR.TRESGScore", "TR.EnvironmentPillarScore", "TR.SocialPillarScore", "TR.GovernancePillarScore"]
parameters= {'Frq':'Q', 'SDate':'2010-12-31','EDate':'2024-12-31'}
try:
for idx, chunk in enumerate(chunk_list(ISIN_list, chunk_size)):
df = rd.get_data(
chunk,
fields=fields,
parameters=parameters)
if idx > 0:
df.append(df)
print(f'{len(chunk)} chunks completed')
except rd.errors.RDError as e:
print("RDError code :", e.code)
print("RDError message:", e.message)If you would like more help, would you mind sharing with us the list of ISINs in a comment to this answer? You can make such comments private so that only moderators (and yourself) can see them.
1
Answers
-
Hi
@jonathan.legrand,thank you for your answer.
The try except loop worked perfectly for me, thanks!
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛