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
32 8 6 5

How do I fix this error?

How do I fix this error?

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
ek.set_log_level(logging.DEBUG)
 
#connects to Bill's Eikon terminal
ek.set_app_key('XXXX')
 
#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,
                    ['TR.RNSFilerName',
                     'TR.RNSAnnouncedDate',
                     'TR.RNSTransactionType',
                     'TR.RNSARNumShrsTransacted',
                     'TR.RNSARPctOSTransacted',
                     'TR.RNSARTransactionPrice',
                     'TR.RNSARMktValTransaction',
                     'TR.RNSARTotShrsPostTrans',
                     'TR.RNSARPctOSPostTrans'])
    df = tmp_df.append(df)
 
 
#set boundary dates of the download
end_date = date.today()
 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'},
           inplace=True)
 
#create file name and export as CSV
todays_date = date.today()
 todays_date_str = datetime.strftime(todays_date, "%Y%m%d")
 df.to_csv('Daily API Download_' + todays_date_str + '.csv')


eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-apiapierror
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

· Write an Answer
Upvotes
39.4k 77 11 27

@bill39

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):
        try:
            tmp_df, e = ek.get_data(ric_chunk, 
                                    ['TR.RNSFilerName', 
                                     'TR.RNSAnnouncedDate',
                                     'TR.RNSTransactionType',
                                     'TR.RNSARNumShrsTransacted',
                                     'TR.RNSARPctOSTransacted',
                                     'TR.RNSARTransactionPrice',
                                     'TR.RNSARMktValTransaction',
                                     'TR.RNSARTotShrsPostTrans',
                                     'TR.RNSARPctOSPostTrans'])
            df = tmp_df.append(df)
            break
        except ek.EikonError as err:
            if err.code == 400:
                pass
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 reportpyeikon.20201028.05-40-08.zip Do you have any other suggestions? Thanks

@bill39

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

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.