Search code examples
pythontwittertweepy

Looking up tweets with tweepy using tweet ids stops after a few tweets - user suspended error


I have a dataset with tweet ids and I'd like to look up the tweets using Tweepy and save them in a csvfile.

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

api = tweepy.API(auth, wait_on_rate_limit=True)

def get_tweet_text(tweet_id):
    tweet = api.get_status(tweet_id)
    return tweet.text

with open('NAACL_SRW_2016_cleaned.csv', 'a') as csvfile_clean:  
    writer = csv.writer(csvfile_clean, delimiter=';')
    writer.writerow(['ID', 'Form of Hate Speech', 'Tweet'])                 

    with open('NAACL_SRW_2016.csv') as csvfile:
        csv_reader: object = csv.reader(csvfile, delimiter=',')
        for row in csv_reader:
            id_of_tweet = (row[0])
            hate = (row[1])
            tweet = get_tweet_text(id_of_tweet)
            print(tweet)

            writer = csv.writer(csvfile_clean, delimiter=';')
            writer.writerow([id_of_tweet, hate, tweet])

The code works fine, but it stops after a few tweets and I get the error message below. However, I'm not suspended - I don't get any kind of message about that on my account and I can also still stream tweets just fine. I've tried different IPs and regenerated the keys, but I always get said error. Anyone experienced something similar? If you have any tips on what I could try to make it work, I'd be very grateful.

So Drasko just said he was impressed the girls cooked half a chicken.. 
They cooked a whole one  #MKR
Drasko they didn't cook half a bird you idiot #mkr
Hopefully someone cooks Drasko in the next ep of #MKR
of course you were born in serbia...you're as fucked as A Serbian Film
These girls are the equivalent of the irritating Asian girls #MKR  
Lost the plot - where's the big Texan with the elephant sized steaks

tweepy.error.TweepError: [{'code': 63, 'message': 'User has been 
suspended.'}]

Solution

  • That error indicates that the user who wrote the tweet you're searching for has been suspended, not that you have. It is the value returned by the tweepy api for error code 63 as listed here https://developer.twitter.com/en/docs/basics/response-codes.html .

    The twitter response codes sheet states that code 63 means The user account has been suspended and the information cannot be retrieved.

    You will not be able to access this information using the api. There is no work around.