Python 推文机器人跟随代码不起作用



我正在构建一个推文机器人,运行我的代码时不断收到错误,这仅在我尝试添加代码以关注任何关注我的人后才出现(我在再次运行之前从文本文件中删除推文,错误是由于跟随人们的部分):

import tweepy, time
CONSUMER_KEY = 'KEY'
CONSUMER_SECRET = 'KEY'
ACCESS_KEY = 'Key'
ACCESS_SECRET = 'Key'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
for follower in tweepy.Cursor(api.followers).items():
    follower.follow()
filename=open('file.txt','r')
tweets=filename.readlines()
filename.close()
for line in tweets:
    api.update_status(line)
    print line, time.strftime("%H:%M:%S")
    time.sleep(120)

这是错误

File "tweetbot.py", line 19, in <module>
api.update_status(line)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/tweepy/api.py", line 194, in update_status
)(post_data=post_data, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 245, in _call
return method.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 229, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{u'message': u'Status is a duplicate.', u'code': 187}]
如果你

有相同的推文,Tweepy 不让你发推文......

所以你可以这样做——

for status in tweepy.Cursor(api.user_timeline).items():
        api.destroy_status(status.id)

相关内容

最新更新