簡體   English   中英

Python Tweetbot遵循代碼無法正常工作

[英]Python tweetbot follow code won't work

我正在構建一個tweetbot,並且在運行我的代碼時不斷收到錯誤,該錯誤僅在我嘗試添加代碼以跟隨關注我的任何人之后才會顯示(我在再次運行前從文本文件中刪除了tweet,該錯誤是由於該部分跟着人們回來):

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM