Tweepy: Unable to Retweet using Tweepy Python, gives AttributeError

Viewed 260

My Twitter bot was working till 2019, before I stopped running the script. Today when I tried to run it up again, it started to give errors. Hence I updated Tweepy to the latest version. But the Retweet and like functionality is not working for me. I tried to scour the documentation but couldn't find the relevant change I may be required to make.

Here is the code snippet and the relevant part of the traceback:

Code

for tweet in tweepy.Cursor(api.search_tweets, q='30daysofcode', lang= 'en').items(100):
    print(tweet)

    try:
        if tweet.user.id == mybot.id:
            continue

        print ("\n\n Found tweet by: @" + tweet.user.screen_name)
        print (tweet.text)
        if (tweet.retweeted == False) or (tweet.favorited == False):
            #print(tweet.id)

            tweet.retweet()
            tweet.favorite()
            break       
            print ("retweeted and favorited")
        if tweet.user.following == False:
            tweet.user.follow()
            print ("followed the user")

    except tweepy.TweepError as e:
        #print e.reason
        sleep(10)
        continue

    except StopIteration:
        breakfor tweet in tweepy.Cursor(api.search_tweets, q='30daysofcode', lang= 'en').items(100):
    print(tweet)

    try:
        if tweet.user.id == mybot.id:
            continue

        print ("\n\n Found tweet by: @" + tweet.user.screen_name)
        print (tweet.text)
        if (tweet.retweeted == False) or (tweet.favorited == False):
            #print(tweet.id)

            tweet.retweet()
            tweet.favorite()
            break       
            print ("retweeted and favorited")
        if tweet.user.following == False:
            tweet.user.follow()
            print ("followed the user")

    except tweepy.TweepError as e:
        #print e.reason
        sleep(10)
        continue

    except StopIteration:
        break

Traceback

Traceback (most recent call last):
  File "30daysofcodeBot.py", line 26, in <module>
    tweet.retweet()
  File "/media/sid21g/Dev/github-dev/CodingNinjas_DataScience_MachineLearning/cnml/lib/python3.6/site-packages/tweepy/models.py", line 369, in retweet
    return self._api.retweet(self.id)
AttributeError: 'NoneType' object has no attribute 'retweet'

Full output and traceback: https://pastebin.com/SGesTP7E

I think it could be due to the fact that in Status, api_=None, (see full output and traceback link) but how may I change it? Does it show faulty authentication? But then I won't be able to even fetch Tweets right?

1 Answers
Related