Tweepy and Python: how to list all followers
<p>With tweepy in Python I'm looking for a way to list all followers from one account, with username and number of followers.
Now I can obtain the list of all ids in this way:</p>

<pre><code>ids = []
for page in tweepy.Cursor(api.followers_ids, screen_name="username").pages():
    ids.extend(page)
    time.sleep(1)
</code></pre>

<p>but with this list of ids I can't obtain username and number of followers of every id, because the rate limit exceed...
How I can complete this code?</p>

<p>Thank you all!</p>

<p>On the REST API, your are allowed <a href="https://dev.twitter.com/rest/public/rate-limiting" rel="nofollow">180 queries every 15 minutes</a>, and I guess the Streaming API has a similar limitation. You do not want to come too close to this limit, since your application will eventually get blocked even if you do not strictly hit it.
Since your problem has something to do with the rate limit, you should put a sleep in your <code>for</code> loop. I'd say a <code>sleep(4)</code> should be enough, but it's mostly a matter of trial and error there, try to change the value and see for yourself.</p>

<p>Something like</p>

<pre><code>sleeptime = 4
pages = tweepy.Cursor(api.followers, screen_name="username").pages()


while True:
    try:
        page = next(pages)
        time.sleep(sleeptime)
    except tweepy.TweepError: #taking extra care of the "rate limit exceeded"
        time.sleep(60*15) 
        page = next(pages)
    except StopIteration:
        break
   for user in page:
       print(user.id_str)
       print(user.screen_name)
       print(user.followers_count)
</code></pre>

python twitter tweepy