超过速率限制时发送Tweepy多个身份验证处理程序



我需要在很短的时间内获得大量推文,并且希望在多个身份验证处理程序之间切换(我有20个不同的推特开发人员帐户(。我在Tweepy文档中没有发现任何与此问题相关的内容,并看到了这个方法,但它不起作用,我不确定,我想是因为不同的API版本。

auths = []
for consumer_key, consumer_secret, access_key, access_secret in twitter_accs:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
auths.append(auth)
# api
api = tweepy.API(auths)
currentCursor = tweepy.Cursor(api.search, q = 'bitcoin')
c = currentCursor.items()
switch = 0
api.auth_idx = switch
tweets = []
maxId = 0
while True:
try:
for tweet in c:
tweets.append(tweet)
maxId = tweet.id
except tweepy.TweepError as e:
print(e)
print("---------------------------Rate limit exceeded.---------------------------")
print("switching keys...")
switch += 1
api.auth_idx = switch           # naechster Key
currentCursor = tweepy.Cursor(api.search, q='bitcoin', max_id=maxId)

得到这个错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~AppDataLocalTemp/ipykernel_13904/1614165536.py in <module>
17 while True:
18     try:
---> 19         for tweet in c:
20             tweets.append(tweet)
21             maxId = tweet.id
~AppDataLocalProgramsPythonPython38libsite-packagestweepycursor.py in __next__(self)
49 
50     def __next__(self):
---> 51         return self.next()
52 
53     def next(self):
~AppDataLocalProgramsPythonPython38libsite-packagestweepycursor.py in next(self)
241         if self.current_page is None or self.page_index == len(self.current_page) - 1:
242             # Reached end of current page, get the next page...
--> 243             self.current_page = self.page_iterator.next()
244             while len(self.current_page) == 0:
245                 self.current_page = self.page_iterator.next()
~AppDataLocalProgramsPythonPython38libsite-packagestweepycursor.py in next(self)
130 
131         if self.index >= len(self.results) - 1:
--> 132             data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kwargs)
133 
134             if hasattr(self.method, '__self__'):
~AppDataLocalProgramsPythonPython38libsite-packagestweepybinder.py in _call(*args, **kwargs)
251                 return method
252             else:
--> 253                 return method.execute()
254         finally:
255             method.session.close()
~AppDataLocalProgramsPythonPython38libsite-packagestweepybinder.py in execute(self)
174                 auth = None
175                 if self.api.auth:
--> 176                     auth = self.api.auth.apply_auth()
177 
178                 # Request compression if configured
AttributeError: 'list' object has no attribute 'apply_auth'

根据Tweepy文档,tweepy.API方法的参数不能是列表。为什么不创建一个经过身份验证的api列表,就像创建一个身份验证列表一样?

最后,要小心,因为你的尝试可能违反了Twitter开发者的条款。

最新更新