Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Eikon Data APIs /

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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

avatar image
Question by bill39 · Feb 24, 2020 at 05:51 PM · eikoneikon-data-apiworkspacepythonworkspace-data-apirefinitiv-dataplatform-eikonjson

Error code 408 | Request timeout occured - JSON request

In Terminal I try to run my python file that should download a large quantity of data as a CSV file.

I get the error code 408. Something about a JSON request. How do I fix this?


(base) U:\Castellain\refinitiv>python dailyAPIcode.py

Request timeout occured

Traceback (most recent call last):

File "dailyAPIcode.py", line 25, in <module>

'TR.RNSARPctOSPostTrans'])

File "C:\Users\william\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\data_grid.py", line 186, in get_data

result = eikon.json_requests.send_json_request(_endpoint, payload, debug=debug)

File "C:\Users\william\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\json_requests.py", line 118, in send_json_request

_check_server_error(result)

File "C:\Users\william\AppData\Local\Continuum\anaconda3\lib\site-packages\eikon\json_requests.py", line 194, in _check_server_error

raise EikonError(int(server_response['ErrorCode']), error_message)

eikon.eikonError.EikonError: Error code 408 | Request timeout occured



FROM THE .PY FILE:



#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
 
#connects to Bill's Eikon terminal
ek.set_app_key('xxxxxxxxxxxxxxxxxxxxx')
 
#Buyback fields with dynamic date constraints for a list of RICs AND export as CSV to U:Castellain/refinitiv

 df,e = ek.get_data("lists('Inv Trust List')","TR.RIC")
 ric_list = df['Instrument'].tolist()
 df, e = ek.get_data(ric_list,
                    ['TR.RNSFilerName',
                     'TR.RNSAnnouncedDate',
                     'TR.RNSTransactionType',
                     'TR.RNSARNumShrsTransacted',
                     'TR.RNSARPctOSTransacted',
                     'TR.RNSARTransactionPrice',
                     'TR.RNSARMktValTransaction',
                     'TR.RNSARTotShrsPostTrans',
                     'TR.RNSARPctOSPostTrans'])
 
end_date = date.today()
 start_date = end_date - timedelta(days=365)
 
 end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
 start_date_str = datetime.strftime(start_date, "%Y-%m-%d")
 
 df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
 mask = (df['RNS Announced Date'] > start_date_str) & (df['RNS Announced Date'] <= end_date_str)
 df = df.loc[mask]
 
df.rename(columns={'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
todays_date = date.today()
 todays_date_str = datetime.strftime(todays_date, "%Y%m%d")
 df.to_csv('Daily API Download_' + todays_date_str + '.csv')



People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by chavalit-jintamalit · Feb 25, 2020 at 02:36 AM

Hi @bill39

Please read the API limitation guide at https://developers.refinitiv.com/eikon-apis/eikon-data-api/docs?content=49692&type=documentation_item

You are mostly exceeding the limitation (10000 records per API call)


I do not know what is inside your lists('Inv Trust List').

Assuming that it is a large list as you mentioned and it may be a culprit.

So you can split them into a smaller list per API call.

Here is a modified code to break the list down into multiple smaller groups.

Please note that I added the time package (import time)

#import packages
import eikon as ek # the Eikon Python wrapper package
import pandas as pd
import numpy as np
import datetime
import time
from datetime import timedelta, date, datetime
from pandas.tseries.offsets import BDay
 
ek.set_app_key('xxxxxxxxxxxxxxxxxxxxx')

#assuming that these are RIC code in ric_list, in your program, it reads from lists
ric_list = ['AAL.L','ABF.L','ADML.L','AHT.L','ANTO.L','AV.L','AZN.L','BAES.L']

#split them into a group of 'ric_per_call' into array_ric_list
ric_per_call = 3 #change to any number of RIC per API call
array_ric_list = []
i = 0
while i < len(ric_lists)/ric_per_call:
    array_ric_list.append(ric_lists[i*ric_per_call:(i+1)*ric_per_call])
    i += 1


#loop API call between groups of RIC
end_date = date.today()
start_date = end_date - timedelta(days=365)

end_date_str = datetime.strftime(end_date, "%Y-%m-%d")
start_date_str = datetime.strftime(start_date, "%Y-%m-%d")

todays_date = date.today()
todays_date_str = datetime.strftime(todays_date, "%Y%m%d")

addHeader = True #this variable to addHeader to csv just one time

for riccodes in array_ric_list:
    print("API calls for:",riccodes)
    df, e = ek.get_data(riccodes,
                    ['TR.RNSFilerName','TR.RNSAnnouncedDate','TR.RNSTransactionType',
                     'TR.RNSARNumShrsTransacted','TR.RNSARPctOSTransacted',
                     'TR.RNSARTransactionPrice','TR.RNSARMktValTransaction',
                     'TR.RNSARTotShrsPostTrans','TR.RNSARPctOSPostTrans'])

    df['RNS Announced Date'] = pd.to_datetime(df['RNS Announced Date'])
    mask = (df['RNS Announced Date'] > start_date_str) & (df['RNS Announced Date'] <= end_date_str)
    df = df.loc[mask]

    df.rename(columns={'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)

    if addHeader:
        df.to_csv('Daily API Download_' + todays_date_str + '.csv', header=True)
        addHeader=False #Only add header one time
    else:
        df.to_csv('Daily API Download_' + todays_date_str + '.csv', mode='a', header=False)
    
    time.sleep(5) #delay between each API call

print('Done')

Here is the result:

API calls for: ['AAL.L', 'ABF.L', 'ADML.L']
API calls for: ['AHT.L', 'ANTO.L', 'AV.L']
API calls for: ['AZN.L', 'BAES.L'] Done
Comment
Jirapongse

People who like this

1 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
Answer by pimchaya.wongrukun01 · Feb 25, 2020 at 02:04 AM

Hello @bill39

Please refer to this question as it is similar.

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
11 People are following this question.

Related Questions

Issue with max request limit for send_json_request(). Data is being truncated beyond 20 RICs

Company trees don't match in Eikon online tool and the Eikon Proxy API

Historical TSRs and Dividends

Access to wire (JSON) API -- I'd like to use Java instead of Python

Retrieve Commodity Flows data using Python API

  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Intelligent Tagging
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open Calais
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • RDMS
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • Workspace SDK
    • Element Framework
    • Grid
  • World-Check Data File
  • 中文论坛
  • Explore
  • Tags
  • Questions
  • Badges