tweepy错误无法发送请求WSAECONNABORTED

时间:2016-04-19 13:51:03

标签: python tweepy

我尝试收集用户的完整关注者列表。该用户拥有超过100,000名粉丝。以下是我正在使用的代码。代码返回几千个关注者,但后来我收到错误“tweepy.error.TweepError:无法发送请求:(10053,'WSAECONNABORTED')。我正在使用Windows机器。

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth, wait_on_rate_limit=True)

# get the followers' screen names 

for user in tweepy.Cursor(api.followers, screen_name="xxxx", count = 200).items():
    print user.screen_name

1 个答案:

答案 0 :(得分:0)

对于那么多粉丝来说,这个过程需要相当长的时间。可达10小时或更长时间。在那段时间内出现某种错误的可能性很大,而且由于你没有以任何方式处理错误,所以每次弹出任何东西都会重新开始。

Twitter使用游标来允许分页。换句话说,如果您知道脚本失败时当前光标是什么,则可以选择上次停止的位置。

使用以下方法跟踪光标:

    current_cursor = user.iterator.next_cursor

打印或将其写入某个文件,因此当脚本失败时,您可以调用:

for user in tweepy.Cursor(api.followers, screen_name="xxxx", count = 200, cursor=current_cursor).items():

这应该可以让你从中断的地方继续。 Original solution posed for a different problem.

相关问题