Hello,
I'm new to the TR API and have been using Python to perform API queries. My script has been running smoothly for about two years. However, when I attempted to run it this week, I encountered various errors.
After reviewing the code in my backup (codebk), it appears that the function get_data([list], 'Instrument') may be causing these errors. Could anyone share their experiences or suggest a solution?
Here are the details of my setup:
Platform: Windows 10 Pro
Python Version: 3.7
Integrated Development Environment (IDE): Spider
Firewall and Antivirus: Disabled
Additionally, I'm using Refinitiv Desktop Gateway 4.0.65 (version 4.0.65101).
Thank you for your assistance.
## Source ## class TR(): def __init__(self): ek.set_app_key('xxxxxxxxxxxx') self.ek_con = ek self.ds_con = DSWS.Datastream(username = 'xxxx', password = 'xxxx') def get_ds_data(self, list_rics, field_name): df_data = pd.DataFrame(columns=['Instrument', 'Datatype', 'Value', 'Currency']) for i in range(0, len(list_rics), 50): list_ric_tmp = list_rics[i:i+50] ric_str = ','.join('<'+x+'>' for x in list_ric_tmp) tmp_df_data = self.ds_con.get_data(tickers=ric_str, fields=[field_name], kind=0) tmp_df_data['Instrument'] = tmp_df_data['Instrument'].str[1:-1] tmp_df_data = tmp_df_data.iloc[:,0:4] # select columns ['Instrument', 'Datatype', 'Value', 'Currency'] df_data = pd.concat([df_data, tmp_df_data], axis=0) return df_data tr_instance = TR() list_nisin_ric = [ '04I.SG^G24', 'ASHC.BO^B23', '8258.HK^B22', ] if list_nisin_ric: df_ds_isin = tr_instance.get_ds_data(list_nisin_ric, 'ISIN') print(df_ds_isin)
## Error Message ## get_data : Exception Occured (<class 'TypeError'>, TypeError("argument of type 'NoneType' is not iterable"), <traceback object at 0x7f05af9a0100>) None Traceback (most recent call last): File "/opt/conda/lib/python3.8/site-packages/DatastreamPy/DS_Response.py", line 159, in get_data if 'DataResponse' in json_Response: TypeError: argument of type 'NoneType' is not iterable --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_84/2317672722.py in <module> 37 # Call get_ds_data on the instance of TR class 38 if list_nisin_ric: ---> 39 df_ds_isin = tr_instance.get_ds_data(list_nisin_ric, 'ISIN') 40 41 print(df_ds_isin) /tmp/ipykernel_84/2317672722.py in get_ds_data(self, list_rics, field_name) 20 21 tmp_df_data = self.ds_con.get_data(tickers=ric_str, fields=[field_name], kind=0) ---> 22 tmp_df_data['Instrument'] = tmp_df_data['Instrument'].str[1:-1] 23 tmp_df_data = tmp_df_data.iloc[:,0:4] # select columns ['Instrument', 'Datatype', 'Value', 'Currency'] 24 df_data = pd.concat([df_data, tmp_df_data], axis=0) TypeError: 'NoneType' object is not subscriptable