1

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

1 Answer 1

3

This was a bug with Tweepy that should be fixed with https://github.com/tweepy/tweepy/commit/451e921210677ee0a618849f189bdfeea497a00c as part of Tweepy v4.2.0.

As a workaround, you can also simply do something like api.retweet(tweet.id) and api.create_favorite(tweet.id).

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.