[英]Avoiding rate limit error using tweepy
I am trying to get some basic information on all the twitter friends that a particular user is following. 我正在尝试获取有关特定用户正在关注的所有Twitter朋友的一些基本信息。 I am using a for loop to get this information but if the user has many friends I get a rate limit error.
我正在使用for循环来获取此信息,但是如果用户有很多朋友,我会遇到速率限制错误。 I am trying and struggling to integrate a way to get around the rate limit into my for loop.
我正在尝试并努力将一种绕过速率限制的方法集成到我的for循环中。 Thank you for any suggestions!!
谢谢您的任何建议!
My original code: 我的原始代码:
data = []
for follower in followers:
carrot = api.get_user(follower)
data.append("[")
data.append(carrot.screen_name)
data.append(carrot.description)
data.append("]")
My attempt at getting around rate limit error: 我试图绕过速率限制错误:
data = []
for follower in followers:
carrot = api.get_user(follower,include_entities=True)
while True:
try:
data.append("[")
data.append(carrot.screen_name)
data.append(carrot.description)
data.append("]")
except tweepy.TweepError:
time.sleep(60 * 15)
continue
except StopIteration:
break
The problem could be it is probably get_user that is throwing the error. 问题可能是可能是get_user引发了错误。 Try putting api.get_user in your exception block
尝试将api.get_user放入您的异常块中
Code below. 下面的代码。
data = []
for follower in followers:
while True:
try:
carrot = api.get_user(follower,include_entities=True)
except tweepy.TweepError:
time.sleep(60 * 15)
continue
except StopIteration:
pass
break
data.append([carrot.screen_name, carrot.description])
How do you intend to store these values? 您打算如何存储这些值? Isn't the following easier to work with
以下难道难道不是一件容易的事吗?
[John, Traveller]
[约翰,旅行者]
as against your code, that stores it as 与您的代码一样,将其存储为
[ "[", John, Traveller, "]" ]
[“ [”,约翰,旅行者,“]”]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.