From edc655bae779ed03123454a3b2edd5de8e9058d8 Mon Sep 17 00:00:00 2001 From: Oren Date: Mon, 7 May 2018 19:50:43 +0300 Subject: [PATCH] Fix `IndexError: list index out of range` bug When the returned `short_name` is null, `fbchat` throws an exception: ```python File "/usr/local/lib/python2.7/site-packages/fbchat/client.py", line 792, in fetchThreadList return [graphql_to_thread(node) for node in j['viewer']['message_threads']['nodes']] File "/usr/local/lib/python2.7/site-packages/fbchat/graphql.py", line 193, in graphql_to_thread last_name=user.get('name').split(user.get('short_name'),1)[1].strip(), IndexError: list index out of range ``` This commit fixes that scenario by accessing the last item in the list via `.pop()` instead of via `[1]` --- fbchat/graphql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/graphql.py b/fbchat/graphql.py index 323a046..d8e1d1b 100644 --- a/fbchat/graphql.py +++ b/fbchat/graphql.py @@ -190,7 +190,7 @@ def graphql_to_thread(thread): url=user.get('url'), name=user.get('name'), first_name=user.get('short_name'), - last_name=user.get('name').split(user.get('short_name'),1)[1].strip(), + last_name=user.get('name').split(user.get('short_name'),1).pop().strip(), is_friend=user.get('is_viewer_friend'), gender=GENDERS.get(user.get('gender')), affinity=user.get('affinity'),