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

RCAS99
RCAS99 Newcomer
edited December 2024 in Eikon Data APIs

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 ek
import pandas as pd
from tqdm import tqdm # Import tqdm for progress tracking
Your Datastream API key
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]
NASDAQ = ek.get_data('0#.IXIC', fields=['TR.RIC'])[0]
Step 1: Merge NYSE and NASDAQ datasets
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 items
last_two = rics[-2:] # Last two items
Print the results
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,

Welcome!

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

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @RCAS99

    I can run the code properly.

    image.png

    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>')
  • Hello @RCAS99

    I can run your code logic successfully with the strategic https://developers.lseg.com/en/api-catalog/lseg-data-platform/lseg-data-library-for-python

    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:

    lseg_1.png

    Resources:

    To let us check the issue in detail, please enable the log as suggested by my colleague.

  • I tried to use your code and i got this

    image.png

    I am using the anaconda online editor.

    Thank you in advance.

  • 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
    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 necessary

    Combine 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}")

  • 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 index

    NYSE=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 Jones

    csv_file_path=r"path"

    Combine all data into a single DataFrame

    rics_df = pd.concat([NYSE, NASDAQ, SP500, DOWJONES], ignore_index=True)

    Remove duplicates

    rics_df.drop_duplicates(subset=['CUSIP'], inplace=True)

    Convert to list

    rics = rics_df['CUSIP'].tolist()

    Extract the first two and last two RICs

    first_two = rics[:2]
    last_two = rics[-2:]

    Print the number of items and the first and last two RICs

    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}")

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @RCAS99

    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.

  • @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 necessary

    Combine 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}")

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @RCAS99

    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.constituents
    image.png

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.