tweepy wait_on_rate_limit 不起作用 [英] tweepy wait_on_rate_limit not working

查看:21
本文介绍了tweepy wait_on_rate_limit 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,首先,我意识到在处理 Twitter 速率限制方面存在许多问题.我不知道为什么,但到目前为止我发现的那些都不适合我.

So, first off, I realize there's a number of questions regarding handling the twitter rate limits. I have no idea why, but none of the ones's I've found so far work for me.

我正在使用 tweepy.我正在尝试获取用户关注者的所有关注者的列表.正如预期的那样,由于 twitter 的速率限制,我无法立即将所有内容都拉下来.我安装了 tweepy v 3.5,因此指的是 http://docs.tweepy.org/en/v3.5.0/api.html.要获取我使用的原始用户的关注者列表:

I'm using tweepy. I'm trying to get a list of all the followers of the followers of a user. As expected, I can't pull everything down all at once due to twitter's rate limits. I have tweepy v 3.5 installed and thus am referring to http://docs.tweepy.org/en/v3.5.0/api.html. To get the list of followers of the originating user I use:

auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)

followerIDs = []
for page in tweepy.Cursor(api.followers_ids, screen_name=originatingUser, wait_on_rate_limit = True, wait_on_rate_limit_notify = True).pages():
    followerIDs.extend(page)

追随者 = api.lookup_users(追随者)

followers = api.lookup_users(follower)

这有点作用,但很快变成:

This works a for a bit but quickly turns into:

tweepy.error.TweepError: [{u'message': u'Rate limit exceeded', u'code': 88}]

我的理论,然后会使用这样的东西为每个 followerID 检索每个用户的关注者:

My theory, would then to retrieve the followers of each user for each followerID using something like this:

for followerID in followerIDs:
        for page in tweepy.Cursor(api.followers_ids, id=followerID, wait_on_rate_limit = True, wait_on_rate_limit_notify = True).pages():
                followerIDs.extend(page)

我遇到的另一个问题是当我试图查找用户名时.为此,它使用 itertools 中的 grouper 函数将关注者分成 100 组(api.lookup_users 一次只能接受 100 个 ID)并使用

The other problem I have is when I'm trying to look up the user names. For this, It use the grouper function from itertools to break the followers up into groups of 100 (api.lookup_users can only accept 100 id's at a time) and use

followerIDs = grouper(followerIDs,100)
for followerGroup in followerIDs:
        followerGroup=filter(None, followerGroup)
        followers = api.lookup_users(followerGroup,wait_on_rate_limit = True)
        for follower in followers:
                print (originatingUser + ", " + str(follower.screen_name))

得到一个不同的错误,即:

That gets a different error, namely:

 TypeError: lookup_users() got an unexpected keyword argument 'wait_on_rate_limit'

我觉得很困惑,因为 tweepy api 建议这应该是一个可以接受的论点.

which I'm finding confusing, becuase the tweepy api suggests that that should be an accepted argument.

对我做错了什么有任何想法吗?

Any ideas as to what I'm doing wrong?

干杯本.

推荐答案

我知道这可能有点晚了,但这里是.

I know this might be a little late, but here goes.

您在 Cursor 构造函数中传递 wait_on_rate_limit 参数,而 tweepy 文档指出它应该在 API() 构造函数上传递.

You pass the wait_on_rate_limit argument in the Cursor constructor, while the tweepy documentation states that it should be passed on the API() constructor.

这篇关于tweepy wait_on_rate_limit 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆