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

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!

eikon-data-apiworkspace#technologypython apiesgerror-400
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.

1 Answer

· Write an Answer
Upvote
Accepted
6.8k 21 3 6

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.

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.

Hi @jonathan.legrand,


thank you for your answer.

The try except loop worked perfectly for me, thanks!

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.