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')


Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.