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

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:
query_result = api_instance.post_analytics_conversations_details_query(query)
a=query_result.conversations
i=[]
for z in range(len(a)):
i.append(a[z])
if 'conversation_end' 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.analytics_conversation_without_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

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)

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

Hi,

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

query_result = api_instance.post_analytics_conversations_details_query(query)

print(query_result)

partcols=['external_contact_id','external_organization_id','flagged_reason','participant_id','participant_name']
sess_cols=['active_skill_ids','acw_skipped','address_from','address_other','address_self','address_to','agent_assistant_id']
media_cols=['codecs','discarded_packets','duplicate_packets','event_time','invalid_packets','max_latency_ms']

for conversation in query_result.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 sess_cols:
if getattr(session, k) != None:
output[k].append(getattr(session, k))
else:
output[k].append('')
for media in session.media_endpoint_stats:
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 "spr_esp_genesys_cc_conversation_detail_data_extract.py", line 208, in
if media != None:
File "/data/data02/dev/edl/corporate/esp/appcode/scripts/spr/spr_env/lib64/python3.6/site-packages/PureCloudPlatformClientV2/models/analytics_media_endpoint_stat.py", line 389, in ne
return not self == other
File "/data/data02/dev/edl/corporate/esp/appcode/scripts/spr/spr_env/lib64/python3.6/site-packages/PureCloudPlatformClientV2/models/analytics_media_endpoint_stat.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

Hi Prashanthi,

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

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