'NoneType' object has no attribute 'get' error for API data

Hello all,
I am trying to download a list of index constituents using the eikon data API, however, i am getting a 'NoneType' object has no attribute 'get' error for this code :
import eikon as ekYour Datastream API key
import pandas as pd
from tqdm import tqdm # Import tqdm for progress tracking
api_key = 'kEY 'Initialize the Eikon API with your API key
ek.set_app_key(api_key)Define the directory to save data
save_directory = r'Enter your directory'Define the chain RIC for NYSE and NASDAQ constituents
NYSE = ek.get_data('0#.NYA', fields=['TR.RIC'])[0]Step 1: Merge NYSE and NASDAQ datasets
NASDAQ = ek.get_data('0#.IXIC', fields=['TR.RIC'])[0]
rics_df = pd.concat([NYSE, NASDAQ], ignore_index=True)Step 2: Check for duplicates in the RIC column and drop them
rics_df.drop_duplicates(subset=['RIC'], inplace=True)Step 3: Convert the 'RIC' column to a list
rics = rics_df['RIC'].tolist()Count the number of items in the rics list
num_items_all = len(rics)Display the first two and last two items
first_two = rics[:2] # First two itemsPrint the results
last_two = rics[-2:] # Last two items
print(f"Number of items in the rics list: {num_items_all}")
print(f"First two items: {first_two}")
print(f"Last two items: {last_two}")
Can someone help me solve this error? I have also tried to use random code to download data for various instruments and variables, and every time I get this error for the get data.
Best,
Answers
-
I can run the code properly.
You can enable logging in the API to verify what the problem is by using the following code (ek.set_log_level).
import eikon as ek ek.set_log_level(1) ek.set_app_key('<APP KEY>')
0 -
Hello @RCAS99
I can run your code logic successfully with the strategic
Example code (the highlight lines are the lines that need to be changed to match the LSEG data library)
import lseg.data as ld import pandas as pd ## Open the Data session ld.open_session() NYSE = ld.get_data('0#.NYA', fields=['TR.RIC']) NASDAQ = ld.get_data('0#.IXIC', fields=['TR.RIC']) rics_df = pd.concat([NYSE, NASDAQ], ignore_index=True) rics_df.drop_duplicates(subset=['RIC'], inplace=True) rics = rics_df['RIC'].tolist() first_two = rics[:2] # First two items last_two = rics[-2:] # Last two items print(f"Number of items in the rics list: {num_items_all}") print(f"First two items: {first_two}") print(f"Last two items: {last_two}")
Result:
Resources:
- Upgrade from using Eikon Data API to the Data library article
- LSEG Data Library for Python and its Configuration Process article
To let us check the issue in detail, please enable the log as suggested by my colleague.
0 -
I tried to use your code and i got this
I am using the anaconda online editor.
Thank you in advance.
0 -
Thanks, it worked for me as well. However, I am unable to retrieve data for stocks in this code . Can you help me with that?
import pandas as pd
Retrieve data from Chain objects and convert them into listsAdjust the method/attribute according to your API (e.g.,.to_list()
or.data
)NYSE_list = list(NYSE) # Replace with NYSE.to_list() or similar if necessary
Combine all lists into one and remove duplicates
NASDAQ_list = list(NASDAQ) # Replace with NASDAQ.to_list() or similar if necessary
SP500_list = list(SP500) # Replace with SP500.to_list() or similar if necessary
DOWJONES_list = list(DOWJONES) # Replace with DOWJONES.to_list() or similar if necessarymerged_list = list(set(NYSE_list + NASDAQ_list + SP500_list + DOWJONES_list))
Optionally, sort the merged list (optional step)merged_list.sort()
Print resultsprint(f"Merged list ({len(merged_list)} items): {merged_list}")
Save the merged list to a CSV file if neededoutput_file = "merged_list.csv"
pd.DataFrame({'RIC': merged_list}).to_csv(output_file, index=False)
print(f"Data saved successfully to {output_file}")0 -
Hi, yes now i am able to run the code, however i want to retrieve a unique list of RICS for all this indexes but i am getting errors.
Retrieve data for each indexNYSE=Chain("0#.NYA")
NASDAQ=Chain("0#.IXIC")
SP500=Chain("0#.SPX")
DOWJONES =Chain("0#.DJA")NYSE = ld.get_data(NYSE, fields=['TR.CUSIP']) # NYSE
NASDAQ = ld.get_data(NASDAQ, fields=['TR.CUSIP']) # NASDAQ
SP500 = ld.get_data(SP500, fields=['TR.CUSIP']) # S&P 500
DOWJONES = ld.get_data(DOWJONES, fields=['TR.CUSIP']) # Dow Jonescsv_file_path=r"path"
Combine all data into a single DataFramerics_df = pd.concat([NYSE, NASDAQ, SP500, DOWJONES], ignore_index=True)
Remove duplicatesrics_df.drop_duplicates(subset=['CUSIP'], inplace=True)
Convert to listrics = rics_df['CUSIP'].tolist()
Extract the first two and last two RICsfirst_two = rics[:2]
Print the number of items and the first and last two RICs
last_two = rics[-2:]print(f"Number of items in the rics list: {len(rics)}")
print(f"First two items: {first_two}")
print(f"Last two items: {last_two}")#Save the complete DataFrame as a CSV file at the end
rics_df.to_csv(csv_file_path, index=False)print(f"Final data saved successfully to {csv_file_path}")
0 -
According to the log, the API is unable to connect to the API Proxy.
Please refer to the Eikon Data API and Refinitiv Data Library - Troubleshooting article to verify what the problem is.
0 -
@Jirapongse i already have solved that problem thanks. However, can you help me with this code:
import pandas as pd
Retrieve data from Chain objects and convert them into listsAdjust the method/attribute according to your API (e.g.,
.to_list()
or
.data
)
NYSE_list = list(NYSE) # Replace with NYSE.to_list() or similar if necessary
NASDAQ_list = list(NASDAQ) # Replace with NASDAQ.to_list() or similar if necessary
SP500_list = list(SP500) # Replace with SP500.to_list() or similar if necessary
DOWJONES_list = list(DOWJONES) # Replace with DOWJONES.to_list() or similar if necessaryCombine all lists into one and remove duplicates
merged_list = list(set(NYSE_list + NASDAQ_list + SP500_list + DOWJONES_list))
Optionally, sort the merged list (optional step)
merged_list.sort()
Print results
print(f"Merged list ({len(merged_list)} items): {merged_list}")
Save the merged list to a CSV file if needed
output_file = "merged_list.csv"
pd.DataFrame({'RIC': merged_list}).to_csv(output_file, index=False)
print(f"Data saved successfully to {output_file}")0 -
Please explain more about the issue.
To get a list of RICs from Chain, you can use the constituents property.
NYSE=Chain("0#.NYA")
NYSE.constituents0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 556 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 652 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛