Legacy Dev Forum Posts

 View Only

Sign Up

TypeError: 'StatisticalResponse' object is not subscriptable

  • 1.  TypeError: 'StatisticalResponse' object is not subscriptable

    Posted 06-05-2025 18:08

    hnin | 2022-05-11 09:56:28 UTC | #1

    Hi, I have received the response from the API call postanalyticsusersaggregatesquery(). The data is [{'interval': '2022-05-10T00:00:00.000Z/2022-05-10T12:00:00.000Z', 'metrics': [{'metric': 'tAgentRoutingStatus', 'qualifier': 'INTERACTING', 'stats': 'sum': 17837647.0}}, {'metric': 'tAgentRoutingStatus', 'qualifier': 'NOT_RESPONDING', 'stats': { 'sum': 12600.0}}, {'metric': 'tAgentRoutingStatus', 'qualifier': 'IDLE', 'stats': { 'sum': 8063629.0 }}], 'views': None}]

    I tried to perform the above data df = pd.jsonnormalize(data, recordpath = ["metrics"])

    The Error responded is TypeError: 'StatisticalResponse' object is not subscriptable

    However, when I assign the data in a variable and convert to a panda dataframe, it was completely fine.

    Any guidance is appreciated. Thanks.


    John_Carnell | 2022-05-31 20:15:12 UTC | #2

    Hi Hnin,

    Sorry for the delay here. Remember that when you use the Python SDK you are not getting the actual JSON object back from the SDK. Instead, you are getting a Python class back. You are getting a Python class. My suspicion is that a particular API call is trying to parse the JSON and referencing the value as if it were a subscribable variable. If you want to get a consumable map of maps you might want to use the utils.santizeforserialization function call in the utils.py code in our SDK. This will a class and convert it to a dictionary of dictionaries representing the JSON object.

    Hope that helps.

    Thanks, John Carnell Manager, Developer Engagement


    system | 2022-07-01 20:16:07 UTC | #3

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 14691