question

Upvotes
Accepted
1 0 0 0

About error: 'str' object has no attribute 'get'

I'm using rdp to get data of private firms. I modified the code many times, but I kept get error like this. Could someone help me to fix this? Many thanks!

1702504899373.png

Below is my code:

import pandas as pd
import refinitiv.dataplatform as rdp
import time
import logging


def get_info(session, url, firm):
    try:
        endpoint = rdp.Endpoint(session=session,
                                url=url)
        response = endpoint.send_request(
            method=rdp.Endpoint.RequestMethod.GET,
            path_parameters={"permId": firm},
        )
        logging.info(f"{firm} is processing!")
        logging.info(f"Response is {response.status['http_status_code']}")
        if response.is_success:
            try:
                wanted_response=response.data.raw['data']['businessClassification']['trbc']
                logging.info(f"{firm} is completed!")
                return pd.DataFrame([wanted_response],index=[f'{firm}'])
            except AttributeError as e:
                logging.error(f"error for {firm}: {e}!")
        else:
            logging.error(f"error for {firm}: {response.status['http_status_code']}!")
    except Exception as e:
        logging.error(f"An unexpected error occurred for {firm}: {e}")
    return None

# Set configuration
session = rdp.open_platform_session(
    "...",
    rdp.GrantPassword(
        username="...",
        password="....."
    )
)
url="https://api.refinitiv.com/user-framework/mobile/overview-service/v1/corp/business-classification/{permId}"
rdp.configure.config["http.request-timeout"] = 60

# import firm list
df_firm = pd.read_stata(...Data/Match/Match_data/final_company_sample.dta')
firm_list = df_firm['Company_PermID'].tolist()
filtered_list=[]
for value in firm_list:
    if value != "":
        filtered_list.append(value)

# get information of each firm
chunk_size=500
df=pd.DataFrame()
for i in range(0, len(filtered_list), chunk_size):
    chunk = filtered_list[i:i + chunk_size]
    for firm in chunk:
        returned_df=get_info(session, url, firm)
        if returned_df is not None:
            df=pd.concat([df,returned_df],ignore_index=True)
    logging.info(f"Completed processing chunk {i + 1} to {min(i + chunk_size, len(filtered_list))}")
    time.sleep(1)


df.to_excel(".../Data/Industry_TRBC.xlsx",index=False)
#technologyerror
1702504899373.png (142.8 KiB)
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.

Hi,

Please be informed that a reply has been verified as correct in answering the question, and marked as such.

Thank you,

AHS


1 Answer

· Write an Answer
Upvotes
Accepted
79.2k 251 52 74

@qi.chen

Thank you for reaching out to us.

Refinitiv Data Platform Libraries are deprecated APIs.

Please upgrade the application to use the Refintiv Data Library for Python instead. The examples are on GitHub.

Then, you can enble logging in the RD library via the configuration file (refinitiv-data.config.json) to verify what the problem is.

{
  ...
  "logs": {
    "level": "debug",
    "transports": {
      "console": {
        "enabled": false
      },
      "file": {
        "enabled": true,
        "name": "refinitiv-data-lib.log"
      }
    }
  },
...

Otherwise, you can enable logging in the API by using the following code.

import refinitiv.data as rd rd.get_config()["http.request-timeout"] = 60 rd.get_config()["logs.level"] = "debug" rd.get_config()["logs.transports.file.enabled"] = True rd.get_config()["logs.transports.file.name"] = "refinitiv-data-lib.log" rd.open_session()


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.

Thank you very much!

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.