Tweepy:无法使用 Tweepy Python 转推,给出 AttributeError

Tweepy: Unable to Retweet using Tweepy Python, gives AttributeError

在我停止 运行 脚本之前,我的 Twitter 机器人一直工作到 2019 年。今天,当我再次尝试 运行 时,它开始出错。因此我将 Tweepy 更新到最新版本。但是转推和类似功能对我不起作用。我试图搜索文档,但找不到我可能需要进行的相关更改。

这是代码片段和回溯的相关部分:

代码

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 (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'

完整输出和回溯:https://pastebin.com/SGesTP7E

我认为这可能是因为在 Statusapi_=None 中(请参阅完整输出和回溯 link),但我该如何更改它?它是否显示错误的身份验证?但是我什至无法获取推文,对吗?

这是 Tweepy 的一个错误,应该用 https://github.com/tweepy/tweepy/commit/451e921210677ee0a618849f189bdfeea497a00c as part of Tweepy v4.2.0 修复。

作为解决方法,您也可以简单地执行 api.retweet(tweet.id)api.create_favorite(tweet.id).

之类的操作