title: Tweepy - Skip following accounts that are private
body: <p>I have a Twitter bot which is working great. However, I have encountered an issue when it comes to following users which have a private Twitter account.</p>
  <p>The bot will send a follow request, and then keep sending the follow request even though a request has already been sent.</p>
  <p>Is it possible to skip following back accounts that are private?</p>
  <p>Here's the code:</p>
  <pre><code>#!/usr/bin/env python3.8
  #followback.py
  
  import tweepy
  import logging
  from config import create_api
  import time
  
  def get_friends():
      # gets a list of your followers and following
      followers = api.followers_ids(screen_name)
      following = api.friends_ids(screen_name)
  
  logging.basicConfig(level=logging.INFO)
  logger = logging.getLogger()
  
  def follow_followers(api):
      logger.info(&quot;Retrieving and following followers...&quot;)
      for follower in tweepy.Cursor(api.followers).items():
          if not follower.following:
              try:
                  logger.info(&quot;Now following &quot;+ (follower.screen_name))
                  follower.follow()
              except tweepy.TweepError as error:
                  if error.api_code == 160:
                      logger.info(&quot;Already sent a follow request to &quot; + (follower.screen_name) + &quot;. Attempting to skip.&quot;)
  
  def main():
      api = create_api()
      while True:
          follow_followers(api)
          logger.info(&quot;Waiting...&quot;)
          time.sleep(120)
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>
  <p>I have now added some code:</p>
  <pre><code>if error.api_code == 160:
      logger.info(&quot;Already sent a follow request to &quot; + (follower.screen_name) + &quot;. 
  </code></pre>
  <p>Which catches the error and looks neater in the log, but it is filling the log up with:</p>
  <pre><code>INFO:root:Retrieving and following followers...
  INFO:root:Now following &quot;user a&quot;
  INFO:root:Already sent a follow request to &quot;user a&quot;. Attempting to skip.
  INFO:root:Now following &quot;user b&quot;
  INFO:root:Already sent a follow request to &quot;user b&quot;. Attempting to skip.
  INFO:root:Waiting...
  INFO:root:Retrieving and following followers...
  INFO:root:Now following &quot;user a&quot;
  INFO:root:Already sent a follow request to &quot;user a&quot;. Attempting to skip.
  INFO:root:Now following &quot;user b&quot;
  INFO:root:Already sent a follow request to &quot;user b&quot;. Attempting to skip.
  INFO:root:Waiting...
  </code></pre>
  <p>Both user a and user b in this example are private accounts.</p>
  <p>Let me know if you require any further information, thanks.</p>