Home>

While getting the follower information list, the following error occurred and it stopped.
I would like to complete the process by skipping the target that caused the error.
Could you please teach me what to do?

TweepError Traceback (most recent call last)
<ipython-input-3-2e326e8711d8>in<module>
     15 for followerID in followerIDs:
     16 followerData = {}
--->17 data = api.get_user (followerID)
     18 followerData ["ID"] = data.screen_name
     19 followerData ["Name"] = data.name
~ \ anaconda3 \ envs \ test \ lib \ site-packages \ tweepy \ binder.py in _call (* args, ** kwargs)
    250 return method
    251 else:
->252 return method.execute ()
    253 finally:
    254 method.session.close ()
~ \ anaconda3 \ envs \ test \ lib \ site-packages \ tweepy \ binder.py in execute (self)
    232 raise RateLimitError (error_msg, resp)
    233 else:
->234 raise TweepError (error_msg, resp, api_code = api_error_code)
    235
    236 # Parse the response payload
TweepError: [{'code': 63,'message':'User has been suspended.'}]
Corresponding source code
CONSUMER_KEY = "*****"
CONSUMER_SECRET = "*****"
ACCESS_TOKEN = "*****"
ACCESS_TOKEN_SECRET = "*****"
import tweepy
auth = tweepy.OAuthHandler (CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token (ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API (auth, wait_on_rate_limit = True)
search_id = "XXXXX"
followerIDs = tweepy.Cursor (api.followers_ids, id = search_id, cursor = -1) .items ()
followerDatas = []
for followerID in followerIDs:
    followerData = {}
    data = api.get_user (followerID)
    followerData ["ID"] = data.screen_name
    followerData ["Name"] = data.name
    followerData ["Follow"] = data.friends_count
    followerData ["Follower"] = data.followers_count
    followerData ["Description"] = data.description
    followerData ["TweetCount"] = data.statuses_count
    followerDatas.append (followerData)
    print (followerData)
import pandas as pd
pd.set_option ("display.max_rows", 1000)
df = pd.DataFrame (followerDatas) .loc [:, ["ID", "Name", "Follow", "Follower", "TweetCount", "Description"]]
df.to_csv (follower_list + ".csv")
What I tried

Please describe here what you have tried for the problem.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

  • Answer # 1

    The error indicates that the account with the user ID you are trying to obtain is frozen.

    There is a way to use exception handling and skip back to the for loop if an error occurs.

    (Omitted)
    for followerID in followerIDs:
        followerData = {}
        try: try:
            data = api.get_user (followerID)
        except tweepy.TweepError as e:
            print (str (e))
            continue
        followerData ["ID"] = data.screen_name
        followerData ["Name"] = data.name
        followerData ["Follow"] = data.friends_count
        followerData ["Follower"] = data.followers_count
        followerData ["Description"] = data.description
        followerData ["TweetCount"] = data.statuses_count
        followerDatas.append (followerData)
        print (followerData)
    (Omitted)