Legacy Dev Forum Posts

 View Only

Sign Up

Error while converting JSON Object to CSV for Conversation Detail using Python SDK

  • 1.  Error while converting JSON Object to CSV for Conversation Detail using Python SDK

    Posted 06-05-2025 18:08

    Vinay_Katta | 2022-05-16 16:14:09 UTC | #1

    Hi Team,

    Background - Our objective is to extract the Conversation detail data using the Python SDK by calling the PureCloudPlatformClientV2.ConversationsApi() package. We are successful in extracting the data in the JSON format however while converting the data from JSON to CSV, we are facing the challenge.

    Error : TypeError: argument of type 'AnalyticsConversationWithoutAttributes' is not iterable

    Code Snippet: queryresult = apiinstance.postanalyticsconversationsdetailsquery(query) a=queryresult.conversations i=[] for z in range(len(a)): i.append(a[z]) if 'conversationend' in a[z]: print(i[z].conversation_end) else: print('na')

    The data type of the whole conversation is LIST however when we check he datatype of a single conversation by passing the index value, it displays "<class 'PureCloudPlatformClientV2.models.analyticsconversationwithout_attributes.AnalyticsConversationWithoutAttributes'>" instead of LIST.

    We suspect as the data type of individual indices are not LIST, the iteration is failing and throwing the above error.

    Any inputs to resolve this issue will be very much helpful.

    Please let me know if you need any further details. I'll be happy to share.

    Thanks & Regards, Vinay


    anon11147534 | 2022-05-16 16:29:02 UTC | #2

    Hi Vinay,

    You should use a for in loop to iterate over conversations. Also, you shouldn't be accessing the conversation_end attribute like that.

    Here's an example:

    i=[]
    for conversation in query_result.conversations:
        i.append(conversation)
        if conversation.conversation_end is not None:
            print(conversation.conversation_end)

    Vinay_Katta | 2022-05-16 17:58:15 UTC | #3

    Hi Ronan,

    Thank you for the input. The solution you proposed worked for us. We are now in the processing of working on other pieces of the codebase. I'll revert to you in case I need any further input. Thank you so much. Regards, Vinay


    Prashanthi_Bandaru | 2022-05-17 17:33:15 UTC | #4

    Hi,

    While I am trying to get the data for mediaendpointstats using the below code, it is throwing the attribute error.

    queryresult = apiinstance.postanalyticsconversationsdetailsquery(query)

    print(query_result)

    partcols=['externalcontactid','externalorganizationid','flaggedreason','participantid','participantname'] sesscols=['activeskillids','acwskipped','addressfrom','addressother','addressself','addressto','agentassistantid'] mediacols=['codecs','discardedpackets','duplicatepackets','eventtime','invalidpackets','maxlatencyms']

    for conversation in queryresult.conversations: for participant in conversation.participants: for i in cols: if getattr(conversation, i) != None: output[i].append(getattr(conversation, i)) else: output[i].append('') for j in partcols: if getattr(participant, j) != None: output[j].append(getattr(participant, j)) else: output[j].append('') for session in participant.sessions: for k in sesscols: if getattr(session, k) != None: output[k].append(getattr(session, k)) else: output[k].append('') for media in session.mediaendpointstats: if media != None: for h in media_cols: if getattr(media, h) != None: output[h].append(getattr(media, h)) else: output[h].append('')

    print(output)

    ERROR: Traceback (most recent call last): File "sprespgenesysccconversationdetaildataextract.py", line 208, in <module> if media != None: File "/data/data02/dev/edl/corporate/esp/appcode/scripts/spr/sprenv/lib64/python3.6/site-packages/PureCloudPlatformClientV2/models/analyticsmediaendpointstat.py", line 389, in _ne_ return not self == other File "/data/data02/dev/edl/corporate/esp/appcode/scripts/spr/sprenv/lib64/python3.6/site-packages/PureCloudPlatformClientV2/models/analyticsmediaendpointstat.py", line 383, in _eq_ return self._dict_ == other._dict_ AttributeError: 'NoneType' object has no attribute '_dict__'

    Can you please help us to resolve this issue.?

    Thanks, Prashanthi


    anon11147534 | 2022-05-20 10:23:25 UTC | #5

    Hi Prashanthi,

    It's very difficult for me to determine the issue because you haven't put your code in a formatted code block.


    system | 2022-06-20 10:24:12 UTC | #6

    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: 14760