在我停止运行脚本之前,我的Twitter机器人一直运行到2019年。今天,当我试图再次运行它时,它开始出现错误。因此,我将Tweepy更新为最新版本。但Retweet和类似功能并不适用于我。我试图浏览文档,但找不到可能需要进行的相关更改。
下面是代码片段和回溯的相关部分:
码
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
我认为这可能是因为在Status,api_=None中(请参阅完整的输出和跟踪链接),但是如何更改呢?它是否显示出错误的身份验证?但那样我就连推特都找不到了对吧?
发布于 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)这样的事情。
https://stackoverflow.com/questions/69491650
复制相似问题