首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tweepy:无法使用Tweepy重发Tweepy,给出了AttributeError

Tweepy:无法使用Tweepy重发Tweepy,给出了AttributeError
EN

Stack Overflow用户
提问于 2021-10-08 06:48:07
回答 1查看 305关注 0票数 1

在我停止运行脚本之前,我的Twitter机器人一直运行到2019年。今天,当我试图再次运行它时,它开始出现错误。因此,我将Tweepy更新为最新版本。但Retweet和类似功能并不适用于我。我试图浏览文档,但找不到可能需要进行的相关更改。

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

代码语言:javascript
复制
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

溯源

代码语言:javascript
复制
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中(请参阅完整的输出和跟踪链接),但是如何更改呢?它是否显示出错误的身份验证?但那样我就连推特都找不到了对吧?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-29 17:03:57

这是一个带有Tweepy的bug,应该用https://github.com/tweepy/tweepy/commit/451e921210677ee0a618849f189bdfeea497a00c作为Tweepy v4.2.0的一部分来修复。

作为一种解决办法,您也可以简单地做一些像api.retweet(tweet.id)api.create_favorite(tweet.id)这样的事情。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69491650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档