For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles


32 7 5 4

How do I fix this error?

How do I fix this error?


2020-10-20 05:40:08,286 -- pyeikon -- INFO -- Set App Key: None 

2020-10-20 05:40:12,522 -- pyeikon -- INFO -- Response : 500 - {"code":500,"message":"Cannot find module \".\"","statusMessage":"Internal Server Error"} 

2020-10-20 05:40:12,523 -- pyeikon -- INFO -- Port 9000 was retrieved from .portInUse file 

2020-10-20 05:40:12,524 -- pyeikon -- INFO -- Try to handshake on url http://localhost:9000/api/handshake... 

2020-10-20 05:40:12,612 -- pyeikon -- INFO -- Response : 400 - Handshake payload is invalid. 

2020-10-20 05:40:12,613 -- pyeikon -- INFO -- Set Proxy port number to 9000 

2020-10-20 05:40:12,613 -- pyeikon -- INFO -- Port 9000 on local proxy was detected 

2020-10-20 05:40:12,614 -- pyeikon -- DEBUG -- Request:{'Entity': {'E': 'DataGrid_StandardAsync', 'W': {'requests': [{'instruments': ["lists('Inv Trust List')"], 'fields': [{'name': 'TR.RIC'}]}]}}} 

2020-10-20 05:40:31,164 -- pyeikon -- DEBUG -- HTTP Response code: 200 

2020-10-20 05:40:31,165 -- pyeikon -- DEBUG -- HTTP Response: {"ErrorCode":400,"ErrorMessage":"Backend error. 400 Bad Request"} 

2020-10-20 05:40:31,166 -- pyeikon -- ERROR -- Backend error. 400 Bad Request

My code:

It downloads data via the Eikon API and exports them as a CSV each morning. I use Windows Task Scheduler to initiate the Batch file which runs the python file.

#WARNING: the Eikon terminal must be running in order to connect to the API

#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime
from datetime import timedelta, date, datetime
from pandas.tseries.offsets import BDay
import logging.config
#logs info for bug fixing
#connects to Bill's Eikon terminal
#retreive the RICs from Eikon
df_rics,e = ek.get_data("lists('Inv Trust List')","TR.RIC")
#convert that into a list and set as an object
ric_list = df_rics['Instrument'].tolist()
#Slice, loop and concatenate the retrieval request - must be done in order to avoid a backend request timeout which
 #happens when we use too many RICs. n can be toggled below. 
n = 10
 df = pd.DataFrame()
for ric_chunk in [ric_list[i:i + n] 
                  for i in range(0, len(ric_list), n)]:
    tmp_df, e = ek.get_data(ric_chunk,
    df = tmp_df.append(df)
#set boundary dates of the download
end_date =
 start_date = end_date - BDay(2)
#set those dates in the necessary string format
end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
 start_date_str = datetime.strftime(start_date, "%Y-%m-%d")
#denote dates in datetime format
df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
#set the date constraints as an object
mask = (df['RNS Announced Date'] >= start_date_str) & (df['RNS Announced Date'] < end_date_str)
#set the dataframe as only those with values inside the boundary dates
df = df.loc[mask]
#rename some of columns headings, some for compatability purposes - some programs don't like the '£' symbol
df.rename(columns={'RNS Announced Date': 'Transaction Date','RNS AR Price (at Transaction) - £': 'RNS AR Price (at Transaction) GBP',
                    'RNS AR Market Value of Transaction - £': 'RNS AR Market Value of Transaction - GBP'},
#create file name and export as CSV
todays_date =
 todays_date_str = datetime.strftime(todays_date, "%Y%m%d")
 df.to_csv('Daily API Download_' + todays_date_str + '.csv')

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.

Hello all,

For additional details, pertaining to this question, please refer to this previous discussion thread

Hi Zoya, No one responded to my final question in that thread. I note also since then I have been collecting error reports as you suggest. The above error is the core issue I believe. Please will you help me? Ideally if you would call me it would be much appreciated. Thanks

Hi @bill39,

Sorry about that delay.

The reason it happened is, because you did not tag (@), it was very easy for the developer who was in discussion with you to miss your last comment, and it is a very busy time of the year for us. I have mentioned, and you should hear from us soon.

Please zip the log, and attach it in the original question.

I would also update to the latest version of Eikon library 1.1.7, as there has been error logging improvements introduced, so this may allow us to learn more of your issue.

The issue continues to be intermittent, about once a week, correct? Does it mean you run the code every day and it fails roughly 1/7 times, or do I misunderstand?

Show more comments

1 Answer

39.3k 76 11 27


While we're looking into the root cause of the error in the response from the backend, as an immediate workaround you can simply retry the request when you encounter this error. E.g. the following code snippet retries the request up to two times when "Backend error. 400 Bad Request " is encountered.

for ric_chunk in [ric_list[i : i + n] for i in range(0, len(ric_list), n)]:
    for j in range(3):
            tmp_df, e = ek.get_data(ric_chunk, 
            df = tmp_df.append(df)
        except ek.EikonError as err:
            if err.code == 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.

Hello @bill39,

Did you have a chance to try the suggestion from @Alex Putkov.?

I agree that this may be the best approach to take, as just like an umbrella guarding from many types of rain, this defensive coding will allow your script to proceed successfully in an event of many kind potential outage, network connectivity, server overloaded, etc.

Hi @zoya.farberov and @Alex Putkov, I have implemented the error catch workaround you have suggested. It worked yday but today produced the attached error Do you have any other suggestions? Thanks


The defensive code that I suggested was to protect specifically against occasional time outs from the backend. There's no code that can protect you from every eventuality. The log you shared indicates that Eikon API Proxy was unavailable and did not respond to the handshake request. One reason this could happen is if Eikon application was not running or was not signed in. Unfortunately from this log alone we cannot say definitively why Eikon API Proxy was unavailable. To establish the root cause would require creating several different logs all with higher logging level than the standard logs created by default.

Show more comments