Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For some Twitter accounts get_user_following() results in list index out of range #62

Closed
shafin191 opened this issue Apr 13, 2024 · 1 comment

Comments

@shafin191
Copy link

shafin191 commented Apr 13, 2024


check_num = 0
user_prob = []

for k in df_acc_list:
    user_id_store = []
    check_num = check_num + 1
    try:
        user_following3 = client.get_user_following(k)
    except:
        print(str(k) + ' was a problem.')
        user_prob.append(k)
        time.sleep(20)
        continue
    
    for i in range(len(user_following3)):
        try:
            des_url = user_following3[i].description_urls[0]['expanded_url']
        except:
            des_url = None
        user_id_store.append({
            'User_ID':k,
            'Following_ID': user_following3[i].id,
            'Verified': user_following3[i].is_blue_verified,
            'User_Description': user_following3[i].description,
            'Description_URL': des_url,
            'Like_Count': user_following3[i].favourites_count,
            'Follower_Count': user_following3[i].followers_count,
            'Friend_Count': user_following3[i].following_count,
            'Location': user_following3[i].location,
            'UserName': user_following3[i].name,
            'ScreenName': user_following3[i].screen_name,
            'Total_Posts':user_following3[i].statuses_count,
            'User_Verified': user_following3[i].verified
        })

    time.sleep(20)
    if check_num%100 == 0:
        time.sleep(60*3)

For some accounts client.get_user_following(k) throws IndexError: list index out of range. Checked with two different versions 1.3.16 and 1.4.7.

Error Message:

IndexError                                Traceback (most recent call last)
/tmp/ipykernel_162588/1999871064.py in <module>
----> 1 client.get_user_following(user_id = '370279585')

~/anaconda3/lib/python3.9/site-packages/twikit/client.py in get_user_following(self, user_id, count, cursor)
   2472             A list of User objects representing the users being followed.
   2473         """
-> 2474         return self._get_user_friendship(
   2475             user_id,
   2476             count,

~/anaconda3/lib/python3.9/site-packages/twikit/client.py in _get_user_friendship(self, user_id, count, endpoint, cursor)
   2367             entry_id = item['entryId']
   2368             if entry_id.startswith('user'):
-> 2369                 user_info = find_dict(item, 'result')[0]
   2370                 results.append(User(self, user_info))
   2371             elif entry_id.startswith('cursor-bottom'):

IndexError: list index out of range

@d60
Copy link
Owner

d60 commented Apr 13, 2024

@shafin191
You can solve this problem by switching off the 'Quality filter' on Twitter.
The steps are as follows:

  1. Open Twitter settings.
  2. Select "Notifications."
  3. Choose "Filters."
  4. Uncheck the "Quality filter" option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants