question

Upvotes
Accepted
3 0 0 1

TRKD - result.json()['GetInterdayTimeSeries_Response_5']['MetaFields']['NAME_LL'] is None

I'm trying to retrieve data using the following RICs one by one, and for each result I need the indname = result.json()['GetInterdayTimeSeries_Response_5']['MetaFields']['NAME_LL'].


RIC = ['NLRSLY=ECI', 'DERSL=ECI', 'USRSL=ECI', 'AURSL=ECI', 'GBRSL=ECI', 'PLPMIY=ECI', 'ESRSLY=ECI', 'ITRSL=ECI', 'SGRSL=ECI', 'HKRSL=ECI', 'CHRSL=ECI', 'RURSLY=ECI', 'CARSLS=ECI', 'JPRSLS=ECI', 'BRRSL=ECI', 'NORSL=ECI', 'IERSL=ECI', 'SERSLM=ECI', 'CZRSLY=ECI', 'HURETY=ECI', 'IDRSLS=ECI', 'DKRSLY=ECI', 'MXRTSL=ECI', 'GRRSLY=ECI']


Every time I ran the for loop to get the result, it will return the following error which means the result.json()['GetInterdayTimeSeries_Response_5']['MetaFields']['NAME_LL'] is NONE for this RIC. But the RIC name that caused this error will change if I ran the loop again. And when I use the same code to just retrieve data from one single RIC which caused an error before, it will return the correct indname.

<ipython-input-3-012c1395d5cf> in get_trkd_quotes(token, appid, ric, interval, attempt)
     63     response = result.json()['GetInterdayTimeSeries_Response_5']['Row']
     64 
---> 65     indname = result.json()['GetInterdayTimeSeries_Response_5']['MetaFields']['NAME_LL']
     66 
     67     for dict in response:

TypeError: 'NoneType' object is not subscriptable

The api limitation is not exceeded since I was just requesting less than 10 records every time.

It seems this error cannot be reproduced because the RIC that causes error is changing randomly, what would be the cause of it?

pythonrkd-apirkd
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.

Upvote
Accepted
14.7k 39 12 18

Hi @chuchen.cai,

Most likely you are breaching the data limits on the API calls. I tried your code and added a time delay as such:

for ric in rics:
    time.sleep(2)

and was able to successfully get all the results, multiple times.

Interestingly, when the requests are not throttled, the server omitted the Metafield - Local Name, in the response, which is why your application throws an error.

Expected response:

{
  'GetInterdayTimeSeries_Response_5': {
    'Row': [{
        'CLOSE': -8.9,
        'TIMESTAMP': '2021-01-31T00:00:00+00:00'
      }, {
        'CLOSE': -5.8,
        'TIMESTAMP': '2021-02-28T00:00:00+00:00'
      }
    ],
    'MetaFields': {
      'NAME_LL': 'Retail Sales YY*'
    }
  }
}

Bad response:

{
  'GetInterdayTimeSeries_Response_5': {
    'Row': [{
        'CLOSE': -8.9,
        'TIMESTAMP': '2021-01-31T00:00:00+00:00'
      }, {
        'CLOSE': -5.8,
        'TIMESTAMP': '2021-02-28T00:00:00+00:00'
      }
    ],
    'MetaFields': None
  }
}


I will raise a service ticket on your behalf for this issue.

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.

Upvotes
14.7k 39 12 18

Hi @chuchen.cai01,

Can you post you complete code snippet so that we can help you debug it. Nothing is evident from the snapshot that you have provided.

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.

Upvotes
14.3k 23 8 12

Hello @chuchen.cai01

Besides the complete code snippet that contains your RKD request message which my colleague requested, could you please confirm if you can replicate the issue with the same query parameters on the RKD API Catalog page?


rkdapi.png (178.3 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.

Upvotes
3 0 0 1

@Gurpreet @wasin.waeosri

Thanks for your reply. The code is like :


rics = ['NLRSLY=ECI', 'DERSL=ECI', 'USRSL=ECI', 'AURSL=ECI', 'GBRSL=ECI', 'PLPMIY=ECI', 'ESRSLY=ECI', 'ITRSL=ECI', 'SGRSL=ECI', 'HKRSL=ECI', 'RURSLY=ECI', 'CARSLS=ECI', 'JPRSLS=ECI', 'BRRSL=ECI', 'NORSL=ECI', 'IERSL=ECI', 'SERSLM=ECI', 'CZRSLY=ECI', 'HURETY=ECI', 
                      'IDRSLS=ECI', 'DKRSLY=ECI', 'MXRTSL=ECI', 'GRRSLY=ECI']

trkddata = []

AUTH_URL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/' \
           'TokenManagement_1/CreateServiceToken_1'
token = authorize(user = config['trkd']['username'], pw = config['trkd']['password'], appid = config['trkd']['application'])

appid = config['trkd']['application']


for ric in rics:
    
    today = datetime.today()
    last3month = today - relativedelta(months=+3)
    date_from_monthly = last3month.strftime('%Y-%m-%dT00:00:00')
    date_to =  today.strftime('%Y-%m-%dT00:00:00')

    interval = 'MONTHLY'

    quote_request_message = {
        'GetInterdayTimeSeries_Request_5':{
            'Field': ['CLOSE'],
            'MetaField': ['NAME_LL'],
            'TrimResponse': False,
            'Symbol': ric,
            'StartTime':date_from_monthly,
            'EndTime':date_to,  
            'Interval': interval,
        }
    }

    quote_url = 'https://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_5'
    headers = {
        'content-type': 'application/json;charset=utf-8',
        'X-Trkd-Auth-ApplicationID': appid,
        'X-Trkd-Auth-Token': token
    }

    result = send_request(quote_url, quote_request_message, headers)
    
    response = result.json()['GetInterdayTimeSeries_Response_5']['Row']
    
    indname = result.json()['GetInterdayTimeSeries_Response_5']['MetaFields']['NAME_LL']
    
    trkddata.append(response)


It returns the following error, while every time the ric causes this error is different.

I've seen 'ESRSLY=ECI', 'DERSL=ECI' and 'AURSL=ECI'. But when I request the data for each ric individually using the same code, it will get correct response and indname. I also query the name from the RKD API Catalog page, it also seems to be correct.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-26-691b033f0497> in <module>
     39     response = result.json()['GetInterdayTimeSeries_Response_5']['Row']
     40 
---> 41     indname = result.json()['GetInterdayTimeSeries_Response_5']['MetaFields']['NAME_LL']
     42 
     43     trkddata.append(response)

TypeError: 'NoneType' object is not subscriptable

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.

Upvotes
3 0 0 1

In addition, when the error occurs, the returned response is like this:

{'GetInterdayTimeSeries_Response_5': {'Row': [{'CLOSE': 4.3,
    'TIMESTAMP': '2021-01-31T00:00:00+00:00'},
   {'CLOSE': 0.7, 'TIMESTAMP': '2021-02-28T00:00:00+00:00'}],
  'MetaFields': None}}

The MetaFields is None, which should be 'Retail Sales YY*'

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.

Upvote
14.7k 39 12 18

Hi @chuchen.cai,

I have raised a support ticker # 09807927 for you. You should directly get updates to this case in your email.

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.

Upvotes
3 0 0 1

@Gurpreet

Thanks a lot! The time delay works XD

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.